Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check batch jobs

Status
Not open for further replies.

desi5pure

MIS
Mar 29, 2008
38
US
(SQL Server 2000) - Every morning, I need to check about 30 jobs to see if they ran OK or not; is there a better way of doing this than opening each job separately.
Is there a SP (stored procedure) that can grab status from each job and display so I don't have to open each job separately?
 
Code:
	SELECT DISTINCT j.[name] JobName,
		jh2.[LastRunDateTime],
		jh.run_status [Status],
		j.enabled as Enabled,
		jh.[message] Message
	FROM msdb.dbo.sysjobs j
			LEFT OUTER JOIN (SELECT job_id,
								MAX(CAST(STUFF(STUFF(CAST(jh.run_date as varchar),7,0,'-'),5,0,'-') + ' ' + STUFF(STUFF(REPLACE(STR(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime)) AS [LastRunDateTime]
							FROM msdb.dbo.sysjobhistory jh
							WHERE step_id = 0
							GROUP BY job_id) jh2
				ON j.job_id = jh2.job_id
			INNER JOIN msdb.dbo.sysjobhistory jh
				ON jh2.job_id = jh.job_id
				AND jh2.[LastRunDateTime] = CAST(STUFF(STUFF(CAST(jh.run_date as varchar),7,0,'-'),5,0,'-') + ' ' + STUFF(STUFF(REPLACE(STR(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime)
	WHERE jh.run_status NOT IN (1,3)
		AND jh.step_id = 0

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top