大家好怎样设置一个存储过程使其中任何一个批处理语句出错就执行另一个存储过程(记录日志)然后结束存储过程
注:存储过程有5000行代码,上百个批处理语句
不能每个批处理后面都加一个判断@@ERROR<>0如:
create proc aa
as
begin
p1
select ...
into ...p2
...
....
.
.set xact_abort on
begin tran
p100
...
...
commit tran
endif (@@ERROR=0)
exec test.test.putlog 'succeed'
else
exec test.test.putlog 'failure'
注:存储过程有5000行代码,上百个批处理语句
不能每个批处理后面都加一个判断@@ERROR<>0如:
create proc aa
as
begin
p1
select ...
into ...p2
...
....
.
.set xact_abort on
begin tran
p100
...
...
commit tran
endif (@@ERROR=0)
exec test.test.putlog 'succeed'
else
exec test.test.putlog 'failure'
2000的话就存储过程中调用存储过程,应该是这样吧~
as
begin
exec 被调用proc
if (@@error <> 0)
......
end
as
begin
--p1 (批处理语句1)
select ...
into ... --p2 (批处理语句2)
...
... .
.
. set xact_abort on
begin tran
--p100 (批处理语句100)
...
...
commit tran
end 参考:
if (@@ERROR=0)
exec test.test.putlog 'succeed'
else
exec test.test.putlog 'failure' 我的意思是在这100个批处理语句中
任何一个执行出错
都结束存储过程
并将执行结果写入日志表(调用另外一个存储过程)
as批处理1
if( @error<>0)
goto ErrFlag批处理2
if()
...return 1
ErrFlag:
exec procShowErrMessage
不能每个批处理后面都加一个判断@@ERROR <>0 /Quote]
...
begin try
要捕捉错误的代码
end trybegin catch
如果捕捉到错误,则执行你想要做的事情
end catch--
这个很符合我们的习惯如果是在2000,只能是判断@@error,如果为1,则产生错误,则进行有错误的处理,否则继续执行即可