我在我的recharge
桌子上创建了一个触发器。它更新onaccountregistry
表的余额。
但有时在我的表中插入行时recharge
,它不会触发触发器。然后值不匹配。该recharge
表每次都插入行。
我按如下方式创建了触发器。这不是复制表。我使用的是 SQL Server 2008 企业版。
请帮我解决这个问题
CREATE TRIGGER [dbo].[RechargeRefund]
ON [dbo].[ISRecharge]
FOR INSERT
AS
declare @tin char(9)
declare @depocd char(1)
declare @oldvalue money
declare @newvalue money
begin
select @tin = inserted.tin_subtin from inserted
select @depocd = inserted.updatetype from inserted
select @newvalue = inserted.DepositAmt from inserted
select @oldvalue = Totdeposit from ISOnAcctRegistry where tin_subtin = @tin
end
if @depocd ='1'
begin
update ISOnAcctRegistry
set Totdeposit = @oldvalue + @newvalue
where tin_subtin = @tin
end
if @depocd ='2'
begin
update ISOnAcctRegistry
set Totdeposit = @oldvalue - @newvalue
where tin_subtin = @tin
end
GO