List all jobs that have failed in the last week
/* DESCRIPTION List Jobs that have failed in the last 7 days. CONFIGURATION none Compatibility list: MSSQL2005 MSSQL2008 MSSQL2000 */ SELECT DISTINCT msdb.dbo.agent_datetime(run_date, run_time) as 'RunDateTime', t2.name 'Job Name', T1.step_id AS 'Step_id', T1.step_name AS 'Step Name', case when run_status=0 then 'Failed' when run_status=1 then 'Succeeded' when run_status=2 then 'Retry' when run_status=3 then 'Canceled' else '' end as Status, LEFT(T1.[message],500) AS 'Error Message' FROM msdb..sysjobhistory T1 JOIN msdb..sysjobs T2 ON T1.job_id = T2.job_id WHERE T1.run_status NOT IN (1,4) AND T1.step_id != 0 and msdb.dbo.agent_datetime(run_date, run_time) > DateAdd(day,-7,GetDate())