以前使用此
SQL Agent Jobs,how to document获取有关所有sql Scheduled作业的信息.
如何找出每项工作的最后一次运行的持续时间?我需要秒,分钟和小时(希望不是,但我害怕).
任何人都可以深入了解我如何查询这个?
解决方法
假设你不会有任何超过999小时的工作,这应该给你一个很好的起点:
SELECT j.name,h.run_status,durationHHMMSS = STUFF(STUFF(REPLACE(STR(h.run_duration,7,0),' ','0'),4,':'),[start_date] = CONVERT(DATETIME,RTRIM(run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,3,':')) FROM msdb.dbo.sysjobs AS j INNER JOIN ( SELECT job_id,instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory GROUP BY job_id ) AS l ON j.job_id = l.job_id INNER JOIN msdb.dbo.sysjobhistory AS h ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT,h.run_duration) DESC,[start_date] DESC;