You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/word/新协航_设计文档/数据库建表文档/20131120/费用审核时生成剩余费用的触发器.sql

67 lines
1.8 KiB
MySQL

3 years ago
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 'Ӧ<EFBFBD><EFBFBD>'
when 2 then 'Ӧ<EFBFBD><EFBFBD>' 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 'ʵ<EFBFBD><EFBFBD>'
when 2 then 'ʵ<EFBFBD><EFBFBD>' 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='ʢԴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
and ((cfd.isdeleted is not null)or(cfd.isdeleted<>1))