Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to send list of failed jobs through email using sp_send_dbmail?

$
0
0

I have 2 tables as PackageErrorLog and PackageLog with columns

PackageLogID     ErrorDescription    LogDateTime ----> PackageErrorLog

         1                       XXXXX               2013-06-17

PackageLogID   PackageName           Status      -----> PackageLog

         1                 LoadSfData               F

I am using msdb.sp_send_dbmail proecedure to send email for the list of jobs failed in last 24 hours and with status F.

EXEC msdb.sp_send_dbmail @profile_name='Notification',@recipients='justtesting@jobs.com',@subject='Test',@body='Jobs Failed'
I want to send in subject servername + 'Jobs Failed'

@subject =CASE SUBSTRING(@@SERVERNAME,2,1)WHEN'D'THEN'Dev'WHEN'S'THEN'SIT'WHEN'U'THEN'UAT'ELSE''END+'Jobs Failed'
and in Body the Name of the Job and error message like,

JobName                  Error

LoadSfData            XXXXXX

LoadEfData            XXXXXX

............

How do i set the values for variables @subject and @body?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>