sql server - SQL Scheduled job query, duration of last runs? -


previously used sql agent jobs, how document information sql scheduled jobs.

how can find out duration of last run each job? need seconds, minutes, , hours (hopefully not, i'm afraid).

can give insight how query this?

assuming you're not going have jobs run longer 999 hours, should give starting point:

select     j.name,     h.run_status,     durationhhmmss = stuff(stuff(replace(str(h.run_duration,7,0),         ' ','0'),4,0,':'),7,0,':'),     [start_date] = convert(datetime, rtrim(run_date) + ' '         + stuff(stuff(replace(str(rtrim(h.run_time),6,0),         ' ','0'),3,0,':'),6,0,':'))     msdb.dbo.sysjobs j inner join     (         select job_id, instance_id = max(instance_id)             msdb.dbo.sysjobhistory             group job_id     ) l     on j.job_id = l.job_id inner join     msdb.dbo.sysjobhistory h     on h.job_id = l.job_id     , h.instance_id = l.instance_id order     convert(int, h.run_duration) desc,     [start_date] desc; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -