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

Popular Posts

Failed to execute the package or element. Build errors were encountered

Restore of database 'DataBase_Name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

Get List of logins on SQL Server instance