SQL查询作业执行情况

查询作业的执行情况sql:

复制代码
SELECT [JobName] = JOB.name,    
            [Step] = HIST.step_id,    
            [StepName] = HIST.step_name,    
            [Message] = HIST.message,    
            [Status] = CASE WHEN HIST.run_status = 0 THEN 'Failed' WHEN HIST.run_status = 1 THEN 'Succeeded' WHEN HIST.run_status = 2 THEN 'Retry' WHEN HIST.run_status = 3 THEN 'Canceled' END,    
            [RunDate] = HIST.run_date,    
            [RunTime] = HIST.run_time,    
            [Duration] = HIST.run_duration    
FROM        msdb.dbo.sysjobs JOB    
INNER JOIN msdb.dbo.sysjobhistory HIST ON HIST.job_id = JOB.job_id      
--WHERE    JOB.name = 'jobname'      

ORDER BY HIST.run_date desc, HIST.run_time

本文由 whchina(江城老温)原创发布,转载请注明出处,江城老温 as a thinker。

你可能感兴趣的:(SQL查询作业执行情况)