码迷,mamicode.com
首页 > 数据库 > 详细

SQL查询作业执行情况

时间:2016-04-27 17:07:59      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

查询作业的执行情况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   

step:作业的第几个步骤。其中0为结果。

step:对应步骤的名字。

 即是查作业的历史记录。

SQL查询作业执行情况

标签:

原文地址:http://www.cnblogs.com/wei325/p/5439441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!