O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using datediff() to Measure Runtime

Although the STATISTICS TIME option works fine for displaying the runtime of a single query, it is not as useful for displaying the total elapsed time for a stored procedure. The STATISTICS TIME option generates time statistics for every command executed within the stored procedure. This makes it difficult to read the output, and you would have to add them all up to determine the total elapsed time for the entire stored procedure.

Another way to display runtime for a stored procedure is to capture the current system time right before it starts, capture the current system time as it completes, and display the difference between the two, specifying the appropriate-sized datepart parameter to the datediff() function, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required