Listing Failed Jobs in SQL Server

Hello everyone,

In this article, I will give information about listing the failed jobs in SQL Server.

In some cases, we may want to list the jobs that are not running successfully in SQL Server.

You can easily do this with the help of the code below.

SELECT @@SERVERNAME ServerName,
       j.name 'Job Name',
       js.step_name StepName,
       jh.sql_severity ImportanceLevel,
       jh.message Message,
       msdb.dbo.agent_datetime(jh.run_date, jh.run_time) RunTime
FROM msdb.dbo.sysjobs AS j
    INNER JOIN msdb.dbo.sysjobsteps AS js
        ON js.job_id = j.job_id
    INNER JOIN msdb.dbo.sysjobhistory AS jh
        ON jh.job_id = j.job_id
WHERE jh.run_status = 0
      AND msdb.dbo.agent_datetime(jh.run_date, jh.run_time) > GETDATE() - 1
ORDER BY msdb.dbo.agent_datetime(jh.run_date, jh.run_time) DESC;

When you run the code, you will get a result like the one below.

Listing Failed Jobs in SQL Server

As you can see, unsuccessful jobs are listed.

Good luck to everyone in business and life.

172 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!