mssql 查询作业执行情况,耗时 等
SELECT j.name AS Job_Name ,
h.step_id AS Step_Id ,
h.step_name AS Step_Name ,
h.message AS Message ,
h.run_date AS Run_Date ,
h.run_time AS Run_Time ,
msdb.dbo.agent_datetime(h.run_date, h.run_time)
AS 'RunDateTime' ,
CAST(run_duration / 10000 AS VARCHAR(2)) + N'小时'
+ CAST(( run_duration - run_duration / 10000 * 10000 ) / 100 AS VARCHAR(2)) + N'分钟'
+ SUBSTRING(CAST(run_duration AS VARCHAR(10)),
LEN(CAST(run_duration AS VARCHAR(10))) - 1, 2) + N'秒'
AS run_duration
FROM msdb.dbo.sysjobhistory h
LEFT JOIN msdb.dbo.sysjobs j ON h.job_id = j.job_id
where run_date like '2020____'
ORDER BY run_duration --Job_Name, h.Step_Id