当我运行查询时,它显示多个执行时间,而不是一个。我只想要一个,所以该怎么做才能只打印一个时间戳?
SET STATISTICS TIME ON
DECLARE @firstNum INT, @secondNum INT, @thirdNum INT, @evenSum INT
SET @firstNum = 1
SET @secondNum = 2
set @thirdNum = 2
SET @evenSum = 2
WHILE (@thirdNum <= 4000000)
BEGIN
SET @thirdNum = @firstNum + @secondNum
SET @firstNum = @secondNum
SET @secondNum = @thirdNum
IF (@thirdNum % 2) = 0
SET @evenSum += @thirdNum
END
PRINT 'Answer = ' + CONVERT(VARCHAR, @evenSum)
SET STATISTICS TIME OFF
如果您从代码中删除PRINT 'Answer = ' + CONVERT(VARCHAR, @evenSum)
那么它将不会打印多个执行时间。