How to check status of SQL jobs through query
Use msdb
GO
SELECT distinct j.Name as "Job Name", --j.job_id,
CASE j.enabled
WHEN 1 THEN 'Enable'
WHEN 0 THEN 'Disable'
END as "Job Status", jh.run_date as
[Last_Run_Date(YY-MM-DD)],
CASE jh.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Successful'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Cancelled'
WHEN 4 THEN 'In Progress'
END as Job_Execution_Status
FROM sysJobHistory jh, sysJobs j
WHERE j.job_id = jh.job_id and jh.run_date =
(select max(hi.run_date) FROM sysJobHistory hi WHERE jh.job_id = hi.job_id )-- to get latest date
Comments
Post a Comment
Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You