begin 
            declare @pdctno char(7),@units char(3),@sunit int,@spanel int,@techno char(3)
            declare scrapqty cursor for  select  pdctno, units,spanel,sunit from  sheet1$  
            open scrapqty 
            fetch next from scrapqty into @pdctno,@units,@sunit,@spanel
            while (@@fetch_status=0)             begin
              update proscjhb set procwip=procwip-@sunit where pdctno=@pdctno and techno='37' and units=@units
              fetch next from scrapqty into @pdctno,@units,@sunit,@spanel
            end
            close scrapqty
            deallocate scrapqty
end

解决方案 »

  1.   

    SQL 代码是没什么问题,请检查你的数据,看满足条件的有多少??
      

  2.   

    --你的语句应该这样写
    Update t2 Set t2.procwip=t2.procwip-t1.sunit From sheet1$ t1 Inner Join proscjhb t2 On t1.pdctno=t2.pdctno and t1.units=t2.units
    Or 
    Update t2 Set t2.procwip=t2.procwip-t1.sunit From sheet1$ t1,proscjhb t2 Where t1.pdctno=t2.pdctno and t1.units=t2.units
      

  3.   

    我想把@sunit他们的值显示出来看看请问怎么写语句啊,你能不能给个例子供我参考??谢谢!
      

  4.   

    select t1.sunit from sheet1$ t1,proscjhb t2  Where t1.pdctno=t2.pdctno and t1.units=t2.units
    and t2.techno='37'
      

  5.   

    你的意思是说不需用到游标一次UPDATE就可以了是吗?