Home > Link, Microsoft SQL Server, MSBI, Optimization, Query, Script, SQL Mentalist, SQL PraRup, SQL Query, SQL Server, Technology,, TSQL, Vishal Pawar > BI SQL # 201 : SQL Server DBA Scripts : Job Failure Notification

BI SQL # 201 : SQL Server DBA Scripts : Job Failure Notification

Hi Folks,

In this article we are going to cover How to get Job Failure Notification.

In this post we are going to discuss following points:

  • Problem Statement of SQL Script:
  • Description of SQL Script:
  • SQL Script Output Column
  • SQL Script Code
  • User Level to execute

Problem Statement of SQL Script:

Get job failed notification?

Description of SQL Script:

This script will help in monitoring the job failure.

SQL Script Output Column


SQL Script Code


-- Initialize Variables
SET @PreviousDate = DATEADD(dd, - 7, GETDATE()) -- Last 7 days 
SET @Year = DATEPART(yyyy, @PreviousDate)

SELECT @MonthPre = CONVERT(VARCHAR(2), DATEPART(mm, @PreviousDate

SELECT @Month = RIGHT(CONVERT(VARCHAR, (@MonthPre + 1000000000
                )), 2)

SELECT @DayPre = CONVERT(VARCHAR(2), DATEPART(dd, @PreviousDate))

SELECT @Day = RIGHT(CONVERT(VARCHAR, (@DayPre + 1000000000
                )), 2)

SET @FinalDate = CAST(@Year + @Month + @Day AS INT)

-- Final Logic
SELECT j.[name]
FROM msdb.dbo.sysjobhistory h
INNER JOIN msdb.dbo.sysjobs j ON h.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps s ON j.job_id = s.job_id
    AND h.step_id = s.step_id
WHERE h.run_status = 0 -- Failure
    AND h.run_date > @FinalDate
ORDER BY h.instance_id DESC

User Level to execute


    Hope you will like how to get the Job Failure Notification.

    If you really like reading my blog and understood at least few thing then please don’t forget to subscribe my blog.

If you want daily link and analysis or interesting link go to following website which will give @ your inbox please subscribe our following link resource blog :

Link Resource Website

For More information related to BI World visit my Mentalist Blog

SQL Server Mentalist >> SQL Learning Blog

Business Intelligence Mentalist >> BI World

Infographic Mentalist >> Image worth explaining thousand Words

Microsoft Mentalist >> MVC,ASP.NET, WCF & LinQ

DBA Mentalist >>Advance SQL Server Blog

Microsoft BI Mentalist >> MS BI Development Update

Connect With me on

| FaceBook |Twitter | linkedIn| Google+ | WordPress | RSS |

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: