天天看点

事务回滚处理

select z.* into #tcc3 from d_card_his z where z.update_tag='f'

SELECT CARD_ID AS cardno, SUM(CURRAMT) AS curramt into #tc3

FROM #tcc3

GROUP BY CARD_ID, update_tag

HAVING (update_tag = 'f')

begin transaction upcardtotal

begin

  update salecard set salecard.cardtotal=salecard.cardtotal + #tc3.curramt

  from salecard,#tc3 where salecard.cardno=#tc3.cardno

  update D_CARD_HIS set update_tag='t' from D_CARD_HIS,#tcc3

  where D_CARD_HIS.card_id=#tcc3.card_id and D_CARD_HIS.update_tag='f' and d_card_his.idd=#tcc3.idd

  if (@@error=0)

      commit transaction upcardtotal

  else

      rollback transaction upcardtotal

end

drop table #tcc3,#tc3

GO