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
原文:http://www.cnblogs.com/zhaowenzhong/p/5164042.html