Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Checking Job Outcomes
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

314 Posts

Posted - 04/21/2006 :  13:33:08  Show Profile  Reply with Quote
I got sick and tired of having jobs fail without being notified, because the job was marked as "in process" and never completed its failure, so a failure notice wasn't sent. So I wrote the following script to find all of the jobs that are enabled and email me the last date associated with the job and its success/failure status. This way if a job is really hung up because of a SQL bug, I get notified and can see that its last success date was in the past so I'm clued in to go and take action.

declare @Command varchar(2000)
select @Command = 'select sh.Run_Date, substring(,1, 40) as Name, substring(sh.Message,1,25) as JobOutcome
from msdb.dbo.sysjobs sj inner join (select job_id, max(instance_id) as LastRun
from msdb.dbo.sysjobhistory where job_id in (select job_id from msdb.dbo.sysjobschedules) and step_id = 0 group by job_id) Outcome on Outcome.Job_id = sj.Job_id and sj.enabled = 1
inner join msdb.dbo.sysjobhistory sh on sh.job_id = sj.job_id and sh.instance_id = Outcome.LastRun 
order by'
exec master..xp_sendmail @recipients = 'email.goes@here', @subject = 'Server: Job Outcomes', @query = @Command
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000