SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to keep time elapsed?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

allan8964
Posting Yak Master

249 Posts

Posted - 09/11/2013 :  13:04:46  Show Profile  Reply with Quote
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

USA
37129 Posts

Posted - 09/11/2013 :  13:07:11  Show Profile  Visit tkizer's Homepage  Reply with Quote
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 - 09/11/2013 :  22:57:33  Show Profile  Reply with Quote
It works this way. Any other ways, like using some functions? Thanks.
Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 09/12/2013 :  03:19:04  Show Profile  Reply with Quote
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


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

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/12/2013 :  15:52:16  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000