Sql-server – Halting a multi-step Agent job without resorting to “Quit the job reporting success”

sql-server-2016sql-server-agent

I have a multi-step process that sometime should stop in the middle, not because of any failure but for business reasons which are not failures.

How can I tell Agent to successfully exit the whole job? (Using "Quit the job reporting success" throws a dreaded Yellow Triangle for the job, and the Red Circle for the step, even though there are no errors.)

Since there are many steps, any one of which might legitimately fail, I'd rather not lump everything into one giant Step.

Best Answer

One solution is to use multiple job steps and branch depending on the success/failure condition of the business condition - but that means the job will produce that "dreaded" yellow triangle and red circle for the step.

A second solution is to use 3 jobs and call one of two jobs based on the result of the business condition.

STEP 1 : Do something

STEP x : Test for business condition

    IF dbo.fnBusinessCondition = 1 
       EXECUTE msdb.dbo.sp_start_job 'Job2'
    else
       EXECUTE msdb.dbo.sp_start_job 'Job3'