我执行以后,SAILER的值算不出来?

解决方案 »

  1.   

    你没有为 @day 做初始,所以没有结果:declare @day int ,@acurd numeric(10,3),@avga numeric(10,3)set @day=0   --如果不用这个,@day=@day+1 的值始终为null,因为null+任何值都是nullupdate workers  set @day=@day+1,
         @acurd=case 
           when @day=60 then (select avg(isnull(b.sailer,0)) from (select top 60 sailer from workers where num='20000001' order by updtime asc) as b)
           when @day>60 then (isnull(sailer,0)-isnull(@acurd,0))*0.15+isnull(@acurd,0)     
           else 0 end ,SAI=@acurd
    where num='20000001'
      

  2.   

    我按你的方法试过,不行,前59天的SAILER应该为0,但这里全都有数算出来。
      

  3.   

    给我感觉好象这里的when @day=60 then根本就没有判断一样。