我有一个 sql 作业步骤
像这样
Declare
@Result varchar(255)
exec myprocedure
@Result = @Result output
我想做什么:
如果@Result = 'Error' 然后将作业标记为失败,我该如何实现?
我有一个 sql 作业步骤
像这样
Declare
@Result varchar(255)
exec myprocedure
@Result = @Result output
我想做什么:
如果@Result = 'Error' 然后将作业标记为失败,我该如何实现?
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"
您可以使用 Try Catch
Begin Try
exec myprocedure
@Result = @Result output
End Try
Begin Catch
/*Do whatever you want here*/
End Catch