#2
mywisdom882017-04-03 00:06
|
alter trigger oknumcgxd --第1次运行时,create,
on [dbo].[newmoo_case_cgxd]
for insert
as
begin
declare @caseid bigint
declare @ischeck int
select @caseid = caseid from inserted
select @ischeck = ischeck from inserted
if exists(select id from newmoo_case where id=@caseid and ischeck >='5')
begin
update a set a.oknum=b.productnum,end_date=getdate()
from newmoo_case a,(select caseid,productnum=sum(productnum) from newmoo_case_cgxd where ischeck >='5' group by caseid ) b
where ischeck >='5'and a.id=b.caseid
end
else
begin
insert into newmoo_case(id,oknum,end_date)
select caseid,productnum,getdate() from inserted
end
if exists(select id from newmoo_case where id=@caseid and ischeck ='3')
begin
update a set a.oknum=b.productnum,end_date=getdate()
from newmoo_case a,(select caseid,productnum=sum(productnum) from newmoo_case_cgxd where ischeck ='3' group by caseid ) b
where ischeck ='3'and a.id=b.caseid
end
else
begin
insert into newmoo_case(id,oknum,end_date)
select caseid,productnum,getdate() from inserted
end
end
代码如上 我设置了两个触发器,如果单独写一个,触发器可以正常工作,
但是如果 像上面 把两个触发器写在一起,或者分别做成两个独立的触发器,
都会不工作,请问是什么原因。应该怎么解决,
非常感谢