How do I make a sql job step quit reporting failure

一曲冷凌霜 提交于 2019-12-10 16:45:53

问题


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?


回答1:


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"




回答2:


You can use Try Catch

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

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


来源:https://stackoverflow.com/questions/2206394/how-do-i-make-a-sql-job-step-quit-reporting-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!