34,587
社区成员
发帖
与我相关
我的任务
分享
CREATE TRIGGER [dbo].[deltb] on [dbo].[AdjustTran]
for delete
AS
begin
UPDATE b
SET Amount=a.Amount,TYPE=CASE WHEN a.trantype=0 THEN 1 ELSE a.trantype end
FROM (SELECT NtMchntID AS MchntID,trantype,SUM(d.FactAmount*d.ComputeRate) AS Amount FROM DELETED d WHERE trantype IN(0,1,4,6) GROUP BY NtMchntID,trantype)a
INNER JOIN mchntaccount b ON a.MchntID=b.MchntID
END
CREATE TRIGGER [dbo].[deltb] on [dbo].[AdjustTran]
for delete
AS
BEGIN
declare @trantype int
declare @MchntID char(18)
declare @Amount money
declare cur cursor for SELECT NtMchntID,trantype FROM deleted
open cur
fetch next from cur into @MchntID,@trantype
while @@fetch_status=0
begin
If @trantype=0 or @trantype=1 or @trantype=4 or @trantype=6
Begin
if @trantype=0
begin
set @trantype=1
end
select d.NtMchntID,sum(d.FactAmount*d.ComputeRate) as Amount
into #Temp
from deleted d
group by d.NtMchntID
select @Amount=Amount from #Temp where NtMchntID=@MchntID
update mchntaccount set Type=@trantype,Amount=Amount-@Amount where MchntID=@MchntID
end
fetch next from cur into @MchntID,@trantype
end
END
-- 这个意思??? 最好将想要的结果描述一下。
CREATE TRIGGER [dbo].[deltb] on [dbo].[AdjustTran]
FOR DELETE
AS
update m
set
Type=(select top 1 (case trantype when 0 then 1 else trantype)
from deleted where NtMchntID=t.NtMchntID and trantype in (0,1,4,6)),
Amount=Amount-t.Amount
from
(select NtMchntID,sum(FactAmount*ComputeRate) as Amount
from deleted where trantype in (0,1,4,6) group by d.NtMchntID ) t,
mchntaccount m
where t.NtMchntID=m.MchntID;
GO
CREATE TRIGGER [dbo].[deltb] on [dbo].[AdjustTran]
for delete
AS
BEGIN
declare @trantype int
declare @MchntID char(18)
declare @Amount money
SELECT @MchntID=NtMchntID,@trantype=trantype FROM deleted
If @trantype=0 or @trantype=1 or @trantype=4 or @trantype=6
Begin
if @trantype=0
begin
set @trantype=1
end
select d.NtMchntID,sum(d.FactAmount*d.ComputeRate) as Amount into #Temp from deleted d
group by d.NtMchntID
select @Amount=Amount from #Temp where NtMchntID=@MchntID
update mchntaccount set Type=@trantype,Amount=Amount-@Amount where MchntID=@MchntID
end
END