例子 -
CREATE Procedure sp_combine_tx8_n_17 as
if exists(
select 1 from TableA
where TX_8 in ('201', '219') and TX_17 in ('00001', '00005')
)
BEGIN
declare @total money
select @total = sum(Amount)
from TableA
where TX_8 in ('201', '219') and TX_17 in ('00001', '00005')
Begin tran
delete TableA
where TX_8 in ('201', '219') and TX_17 in ('00001', '00005')
IF (@@Error<>0) GOTO Err_Handling
insert TableA (TX_8, TX_17, Amount, Comment, Yuanshi)
values ('201-219', '00001-5', @total, 'intertest', null)
IF (@@Error<>0) GOTO Err_Handling
Commit Tran
Return 0
Err_Handling:
Print 'Unexpected Error Occured!'
Rollback Tran
Return 1
END