question

zillabaug avatar image
zillabaug asked

checking SQL server agent job status

I have been tasked to write a query the checks the status of a SQL server agent job every 10 seconds and return a status code of 1 to control m (Job scheduler program) if the job succeeded or completed and 0 if the job failed.

Has anyone written a script or stored proc that accomplishes such a taks? i attempted to write a script but I get confused the more I look at it?

If you have any script or stored proc or pointers, please share with me.

tsqlscriptcodesqlserver2014sql server agent
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What have you tried thus far? The job status is in MSDB.dbo.sysjobhistory. This table will have a row for every execution for every job that has ran. You would need to figure out the most recent execution of each job and then check the status.

0 Likes 0 ·

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.