Friday 9 July 2010

MS SQL 2005 Debugging Stored Procedure Performance by printing current time

When you have a very large Stored Procedure which is made up of multiple queries and is slow or is taking a very long tim eto execute, you can place the following in before and after each section so that when you run it through the MS SQL management studio in the messages tab you can see exactly how long each section of the Stored Procedure takes to execute.

print 1
print convert(varchar(10),CURRENT_TIMESTAMP,114)

select ....

print 2
print convert(varchar(10),CURRENT_TIMESTAMP,114) 

select ....

print3
print convert(varchar(10),CURRENT_TIMESTAMP,114)