CruelIO
CruelIO

Reputation: 18634

How do I make a sql job step quit reporting failure

I have a sql job step

like this

Declare 
@Result varchar(255)

exec myprocedure
@Result = @Result output

What I want to do:
if @Result = 'Error' then mark the job as failed, how can I achieve that?

Upvotes: 4

Views: 11402

Answers (2)

codingguy3000
codingguy3000

Reputation: 2835

You can use Try Catch

Begin Try
   exec myprocedure
   @Result = @Result output
End Try

Begin Catch
   /*Do whatever you want here*/
End Catch

Upvotes: 0

Ed Harper
Ed Harper

Reputation: 21505

Add this to the end of your script:

if @Result = 'Error'
    raiserror('The stored procedure returned an error',16,1)

And make sure that on the "Advanced" tab of the step properties, the "on failure action" is set to "Quit the job reporting failure"

Upvotes: 9

Related Questions