首页 > 其他 > 详细

快速获取JOB运行结果

时间:2016-01-27 19:08:10      阅读:120      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!