CREATE TRIGGER [tri_del] ON [TB] 
FOR insert 
AS
----判断插入的数据是否重复
if  (select a.cpbh+convert(char(10),a.sj) from tb a,inserted b where a.cpbh=b.cabh group by a.cpbh+convert(char(10),a.sj))
having count(a.cpbh+convert(char(10),a.sj))>1)>1
----如果重复开如执行以下语句
-----生成相加以后的临时表
select a.cpbh,(sum(a.xls)+sum(a.sp)+sum(a.hl)+sum(a.jp)) as cl,
sum(a.xsl) as xsl,sum(a.sp) as sp,sum(a.hl) as hl,sum(a.jp) as jp
into #a 
from tb a,inserted b
where a.cpbh=b.spbh
group by a.cpbh
----删除重复记录
delete TB from TB a,inserted b 
where a.cpbh=b.cpbh
-----向原表插入调整后的数据
insert into TB (CPBH, sj,cl,xsl,sp,hl,jg )
SELECT CPBH, sj,cl,xsl,sp,hl,jg
from #a