开发者

How do I make a sql job step quit reporting failure

开发者 https://www.devze.com 2022-12-19 01:01 出处:网络
I have a sql job step like this Declare @Result varchar(开发者_运维百科255) exec myprocedure @Result = @Result output

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?


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"


You can use Try Catch

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

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

精彩评论

暂无评论...
验证码 换一张
取 消