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
 General SQL Server Forums
 New to SQL Server Programming
 how to keep time elapsed?

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2013-09-11 : 13:04:46
Hi there,

I have about 20 scripts to run as

exec script1 ...
exec script20


I want to know how long does each of the script piece take. So how can I keep the records of time spent and save them as a file or save them into a table?
Really appreciate your help!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-09-11 : 13:07:11
Use a variable to store getdate() at the start and then use datediff to compare that variable to the current system time.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2013-09-11 : 22:57:33
It works this way. Any other ways, like using some functions? Thanks.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2013-09-12 : 03:19:04
[code]DECLARE @table table (
Procedure varchar(50),
StartTime datetime,
EndTime datetime

INSERT INTO @table VALUES ('Proc1', GETDATE(), NULL)
EXEC Proc1
UPDATE @table SET EndTime = GETDATE() WHERE Procedure = 'Proc1'

INSERT INTO @table VALUES ('Proc2', GETDATE(), NULL)
EXEC Proc2
UPDATE @table SET EndTime = GETDATE() WHERE Procedure = 'Proc2'

...


SELECT * FROM @table[/code]

- Lumbago
My blog-> http://thefirstsql.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-12 : 15:52:16
quote:
Originally posted by allan8964

It works this way. Any other ways, like using some functions? Thanks.


sql profiler

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -