alter PROCEDURE [dbo].[p_rep_test]
as begin
declare @ErrorMessage varchar(8000), @ErrorSeverity int, @ErrorState int,@ErrorNumber int,
@OperType int,@abc int
set @abc=1
BEGIN TRANSACTION update_billofdocumentdetail
begin try
update t_wh_billofdocument
set remark='1234'
where id=15127
if @abc=1
begin
raiserror('%s',16,1,'中断')
return 1
end
end try
begin catch
SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(),@ErrorNumber=ERROR_NUMBER()
if @ErrorSeverity>18 or @ErrorSeverity<0
set @ErrorSeverity=16
if @ErrorState>127 or @ErrorState<1
set @ErrorState=1
begin try
ROLLBACK TRANSACTION update_billofdocumentdetail
end try
begin catch
end catch
set @ErrorMessage='保存失败'
raiserror (@ErrorMessage, @ErrorSeverity,@ErrorState)
return @ErrorNumber
end catch
begin try
COMMIT TRANSACTION update_billofdocumentdetail
end try
begin catch
end catch
end
我执行存储过程:exec p_rep_test
提示是:
(1 行受影响)
消息 50000,级别 16,状态 1,过程 p_rep_test,第 38 行
保存失败
我想在事务里,在运行事务里,当@abc=1,我想把事务中断,并且提示“中断”,而不是“保存失败”的提示,应该如何写sql代码?
回复:事务不能中断