4

我有一个 sql 作业步骤

像这样

Declare 
@Result varchar(255)

exec myprocedure
@Result = @Result output

我想做什么:
如果@Result = 'Error' 然后将作业标记为失败,我该如何实现?

4

2 回答 2

8

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"

于 2010-02-05T10:09:15.310 回答
0

您可以使用 Try Catch

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

Begin Catch
   /*Do whatever you want here*/
End Catch
于 2010-02-05T17:14:32.283 回答