Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Disable SQL Server Agent job on failure

I have a daily scheduled SQL job on SSMS with multiple steps, if any of these steps fail, I want to disable the job in order to prevent the scheduled job from running the following day.

I have currently got this working by setting step 1 to check the value in a control table and only continue if the value is 1. Then on failure of any following steps, jump to step 10 which is a T-SQL script that updates the value in this table to 0

Whilst this does work, I think disabling the job entirely seems cleaner. Is there a way to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Have a step in the job that disables the job (probably either the last or the first) using sp_update_job and then have the other step(s) run that step on failure (and go to the next step on success). You’ll also likely want your disabling step to report a failure after it successfully runs. Just make sure that either the job starts at step 2 or the penultimate step quits the job on success.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading