SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

druer
Constraint Violating Yak Guru

USA
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(sj.name,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 sj.name'
exec master..xp_sendmail @recipients = 'email.goes@here', @subject = 'Server: Job Outcomes', @query = @Command
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000