How to quit a job if some condition is not satisfied in a job step?
I have multiple steps in a job and each step is individual and has one condition true or false. I wanted to add "xp_sendmail" end of each step, and if the condition is false with in the step execute "xp_sendmail" and quit the job.
My aim is to receive a mail with at which step the job is faild
for example like below.
Step 1
if my condition is true, then run some code and go to 2nd step.
if my condition is false execute the below code and quit the job but don't go to next step.
EXEC master.dbo.xp_sendmail
@recipients=N'sqldba@company.com',
@message=N'Job failed at step 1.'
now quit the job.
Step: 2
Here i ahve another condition if it is true run my statements and then "xp_sendmail"
EXEC master.dbo.xp_sendmail
@recipients=N'sqldba@company.com',
@message=N'Job completed successfully.'
If my condition is not true run the below statemets
EXEC master.dbo.xp_sendmail
@recipients=N'sqldba@company.com',
@message=N'Job failed at step 2.'
End of job.