Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Querying the duration of the latest successful SQL Agent Job step


Querying the duration of the latest successful SQL Agent Job step

Author
Message
bsivel
bsivel
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 21
I would like to query the durations of steps in several SQL Agent jobs and write them on a administrative report. Does anyone know how or where to get these values without view the history?

thanks in advance!

bsivel
Timothy Ford-473880
Timothy Ford-473880
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1055 Visits: 446
The core table for this is msdb.dbo.sysjobhistory. You can add a great deal of information by joining to other metadata tables in msdb, but this will get you started:


SELECT SJ.[name], SJH.[step_id], SJH.[step_name], SJH.[run_date],
SJH.[run_time], SJH.[run_duration]
FROM msdb.dbo.[sysjobs] SJ LEFT JOIN
msdb.dbo.[sysjobhistory] SJH ON SJ.[job_id] = SJH.[job_id]
ORDER BY SJ.[name], SJH.[run_date] DESC, SJH.[step_id]



- Tim Ford, SQL Server MVP
http://www.sqlcruise.com
http://www.thesqlagentman.com
http://www.linkedin.com/in/timothyford
bsivel
bsivel
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 21
Thanks Tim - this is exactly what I need. Looks like the duration is in milliseconds. Does that sound right?
Timothy Ford-473880
Timothy Ford-473880
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1055 Visits: 446
Believe it or not, it's actually needs to be parsed out. For example a value of 1442 translates to MM:SS.

- Tim Ford, SQL Server MVP
http://www.sqlcruise.com
http://www.thesqlagentman.com
http://www.linkedin.com/in/timothyford
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search