Search code examples
sqlssmsssms-2012

SSMS Set Statistics Time On/Off prints multiple lines instead of just one


When I run my query, it prints multiple execution times instead of just one. I only want one so what do I need to do to get this to only print one time stamp?

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

Solution

  • If you remove PRINT 'Answer = ' + CONVERT(VARCHAR, @evenSum) from your code then it won't print multiple execution time.

    Here is the example of it.