同志们啊,快帮我看看这个触发器,怎么每次出发完植都是空的!!
alter TRIGGER sum_gz ON [dbo].[jjjlb]
FOR INSERT, UPDATE, DELETE
AS
declare @dailiao_day_salary float
declare @sub_salary float
declare @total float
declare cur_total cursor for
select rq,bh,ppo from inserted
open cur_total
declare @rq varchar(10)
declare @bh varchar(50)
declare @ppo varchar(50)
fetch next from cur_total into @rq,@bh,@ppo
while (@@fetch_status <> -1)
begin
set @sub_salary=(select jbsx from ryda where bh=@bh)
set @dailiao_day_salary=(select dlrx from ryda where bh=@bh)
SET @total=(select sum(sum_sigle) from jjjlb where bh=@bh and rq=@rq and ppo=@ppo )
update jjjlb set sum_sigle=(@sub_salary/208*jssj+@sub_salary/208*1.5+@sub_salary/208*zlbgs+@sub_salary/208*jbsj_b*2+@sub_salary/208*zrbgs+@sub_salary/208*zrbgs*2+yxb_a*2+yxb_a*3)
where bh=@bh and rq=@rq and ppo=@ppo
update jjjlb set total=@total where bh=@bh and rq=@rq and ppo=@ppo
fetch next from cur_total into @rq,@bh,@ppo
end
close cur_total
deallocate cur_total
------解决方案--------------------set @sub_salary=(select jbsx from ryda where bh=@bh)
set @dailiao_day_salary=(select dlrx from ryda where bh=@bh)
SET @total=(select sum(sum_sigle) from jjjlb where bh=@bh and rq=@rq and ppo=@ppo )
--〉
set @sub_salary=isnull((select jbsx from ryda where bh=@bh),0)
set @dailiao_day_salary=isnull((select dlrx from ryda where bh=@bh),0)
SET @total=isnull((select sum(sum_sigle) from jjjlb where bh=@bh and rq=@rq and ppo=@ppo ),0)
------解决方案--------------------把
while (@@fetch_status <> -1)
改成
while (@@fetch_status=0)试试
------解决方案--------------------把游标内的处理过程修改一下试试:
while(@@fetch_status = 0)
begin
select @sub_salary = isnull(jbsx,0), @dailiao_day_salary = isnull(dlrx,0)
from ryda where bh=@bh
select @total = isnull(sum(sum_sigle),0)
from jjjlb where bh=@bh and rq=@rq and ppo=@ppo
update jjjlb set
sum_sigle=(ISNULL(@sub_salary/208*jssj,0)+@sub_salary/208*1.5+
ISNULL(@sub_salary/208*zlbgs,0)+
ISNULL(@sub_salary/208*jbsj_b*2,0)+
ISNULL(@sub_salary/208*zrbgs,0)+
ISNULL(@sub_salary/208*zrbgs*2,0)+
ISNULL(yxb_a*2,0)+
ISNULL(yxb_a*3,0))
where bh=@bh and rq=@rq and ppo=@ppo
...
------解决方案--------------------是青青嗎
------解决方案--------------------現在在哪里啊
------解决方案--------------------如果hellowork(一两清风)大哥,說的,改了沒用的話,
把FOR INSERT, UPDATE, DELETE
改為after INSERT, UPDATE, DELETE 試試