I am using Sql Server Management studio and I’m running a query with a select statement.
At the beginning and end of the query I have a select getdate()
If I run the query with ‘Results To Grid’ instead of ‘Results To Text’ I get VERY different times between these to times (I’ve run several times to eliminate disruption from caching).
These times are obviously generated on the SQL server itself (because they’re part of the query) as opposed to Management Studio, given that why would the result output impact on the time it takes the query to execute?
If it is a multi-part query, e.g.:
My assumption would be that the difference is that SSMS is rendering the results of each part before issuing the next part of the query (or more likely, before advancing to that result set and therefore causing SQL Server to evaluate the last statement). Rendering to a grid probably takes dramatically more time than writing out plain text, so the time may be different.
That’s really the only explanation if the client rendering mode is truly affecting the time between the first and the last GetDate().
If you want true server-side, single statement timing, you may want to look into using SQL Server Profiler to time the execution of the query itself.