Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Testing Times

Author  Topic 

nmarks
Yak Posting Veteran

53 Posts

Posted - 2007-10-09 : 04:28:37
Hi,

I've written a T-SQL script and need to record how long it takes to execute from start to end. It only takes between 5 and 10 seconds but I need to know accurately, ideally including milliseconds.

I have written a short script to show the times at the start and end of execution but these are only shown to the minute. I need greater accuracy. Can anyone help?

Here the code I've written:

Use appropriate_database
DECLARE @t1 DATETIME;
DECLARE @t2 DATETIME;
DECLARE @t3 DATETIME;
SET @t1 = getdate()
print @t1
execute sp_run_job
SET @t2 = getdate()
print @t2

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-09 : 04:34:58
DECLARE @t1 DATETIME

Use appropriate_database

SET @t1 = getdate()

execute sp_run_job

print datediff(ms, @t1, getdate()) as timetakenmilliseconds



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

nmarks
Yak Posting Veteran

53 Posts

Posted - 2007-10-09 : 04:38:28
Great, much appreciated
Go to Top of Page
   

- Advertisement -