IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[tri_ChfeeAudit]')) DROP TRIGGER [dbo].[tri_ChfeeAudit] GO create trigger tri_ChfeeAudit on ch_fee after update as if update ([feestatus]) if (select feestatus from inserted)=0 begin insert into ch_fee_total select inserted.gid,inserted.feetype, (select sum(f.amount) from ch_fee f where f.customername=inserted.customername and f.feetype=inserted.feetype and f.feestatus in(0,8,9) ) total,getdate(), inserted.feetype, case inserted.feetype when 1 then '应收' when 2 then '应付' end dotypeRef, inserted.customername from inserted end go --select * from ch_fee_remain --delete from ch_fee_remain --select * from tsysenumvalue where enumtypeid=99024 IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[tri_Chfeesettlement]')) DROP TRIGGER [dbo].[tri_Chfeesettlement] GO IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[tri_Chfeedo]')) DROP TRIGGER [dbo].[tri_Chfeedo] GO create trigger [tri_Chfeedo] on ch_fee_do after insert as --if (select isdelete from inserted)<>1 begin insert into ch_fee_total select inserted.gid,inserted.feetype, (select sum(cfd.amount) from ch_fee_do cfd where cfd.customername=inserted.customername and cfd.feetype=inserted.feetype and ((cfd.isdeleted is null)or(cfd.isdeleted<>1))) as total,inserted.createtime, inserted.feetype+2, case inserted.feetype when 1 then '实收' when 2 then '实付' end dotype, inserted.customername from inserted end go select * from ch_fee_do order by enterdate desc select * from ch_fee_settlement select * from ch_fee_total order by auditdate select * from ch_fee_do select sum(cfd.amountrmb) from ch_fee_do cfd where cfd.customername='盛源商行' and ((cfd.isdeleted is not null)or(cfd.isdeleted<>1))