Friday, 30 September 2016

Get Number of failure jobs in sql server

We can get the failure jobs using below sql script
select
     JobHistory.server
    ,job.name AS [Job Name]
    ,JobStep.step_name As [Step Name]
    ,JobHistory.sql_severity As [sql Severity]
    ,JobHistory.message
    ,(CASE JobHistory.run_status
            WHEN 0 THEN 'Failed' WHEN 1 THEN 'Succeeded'
            WHEN 2 THEN 'Retry'  WHEN 3 THEN 'Canceled'
            WHEN 4 THEN 'In progress' END) AS Status
    ,JobHistory.run_date as [Run Date]
    ,JobHistory.run_time as [Run Time]
       ,JobHistory.run_duration as [Run Duration]
FROM msdb.dbo.sysjobs AS job
INNER JOIN msdb.dbo.sysjobsteps AS JobStep
 ON JobStep.job_id = job.job_id
INNER JOIN msdb.dbo.sysjobhistory AS JobHistory
ON JobHistory.job_id = job.job_id
WHERE JobHistory.run_status = 0

See the below
 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts