码迷,mamicode.com
首页 > 其他好文 > 详细

快速获取JOB运行结果

时间:2016-01-27 19:11:02      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

IF EXISTS(SELECT *
          FROM   sysobjects
          WHERE  xtype = P
                 AND name = SP_Check_Job_Status)
BEGIN
  DROP PROCEDURE SP_Check_Job_Status
END
GO
CREATE PROCEDURE  [dbo].[SP_Check_Job_Status]
 AS
 BEGIN
    SET NOCOUNT ON
 select  b.name,   a.step_name, msdb.dbo.agent_datetime( run_date, run_time) AS RunDateTime ,  
        a.run_duration,  
         case  when a.run_status=0 then Failed  
         when a.run_status= 1 then Succeeded
         when a.run_status= 2 then Retry
         when a.run_status= 3 then Canceled
         else Unknown  
         end as run_status,  
       a.[message] , 
       run_date
from msdb .dbo. sysjobhistory a inner join msdb .dbo. sysjobs b    on a.job_id =b .job_id 
inner join msdb. dbo.sysjobsteps s on a .job_id = s .job_id and a.step_id = s .step_id
where b .enabled = 1  and a.run_status<>1 and a.run_date>=convert(nvarchar(12),getdate(),112)
    SET NOCOUNT OFF
 END  

 

快速获取JOB运行结果

标签:

原文地址:http://www.cnblogs.com/zhaowenzhong/p/5164042.html

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