34,838
社区成员




use swgl
declare @qsph char(8)
declare @jzph char(8)
declare @dpr char(20)
declare @retractCount int
declare @errMsg char(200)
declare @e int --增加变量,用于存放@@error
declare @disposeCount_1 int
declare @disposeCount_2 int
set @qsph='80000001'
set @jzph='80000010'
set @dpr='赵艳桃'
begin tran retract
update t_print_billlist
set flag='0',kjsj=NULL,kjr=''
where ltrim(rtrim(kcr))=ltrim(rtrim(@dpr)) and
ltrim(rtrim(kjr))=ltrim(rtrim(@dpr)) and
flag='1' and
bill> =@qsph and
bill <=@jzph
select @e=@@error,@disposeCount_1 = @@rowcount
if @e <> 0 goto E_Retract_Fail
print @disposeCount_1
delete from t_print_log
where ltrim(rtrim(optioner))=ltrim(rtrim(@dpr)) and
number> =@qsph and
number <=@jzph and
flag='1'
select @e=@@error,@disposeCount_2 = @@rowcount
if @e <> 0 goto E_Retract_Failset
print @disposeCount_2
-- 检查 处理的数据个数
if @disposeCount_1 <> @disposeCount_2
begin
print 'check_1'
set @retractCount = -1
set @errMsg = '表 t_print_billlist 和 t_print_log 中的数据个数不一致。'
rollback tran retract
return
end
if @disposeCount_1 = @disposeCount_2 and @disposeCount_1 = 0
begin
print 'check_2'
set @retractCount = 0
set @errMsg = '没有要撤销的数据。'
rollback tran retract
return
end
-- 条件符合,可以提交
print 'commit'
commit tran retract
if @@error <> 0 goto E_Retract_Fail
set @retractCount = @disposeCount_1
return
E_Retract_Fail:
print 'Fail'
rollback tran retract
set @retractCount = -1
set @errmsg = '发生错误,撤销未完成'
return
print 'end'
go
BEGIN TRANSACTION
...
update ...
if @@rowcount ...
...
COMMIT TRANSACTION