SQL SERVER的存储过程循环UPDATE语句怎么写?能不能给个例子啊???急......

解决方案 »

  1.   


    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
      

  2.   

    你这个是一次性UPDATE的,我想要循环的.
      

  3.   

    declare cur_Test cursor scroll for
    select type from tb
    for update of typedeclare @fetch_status intopen cur_Testfetch cur_Test
    select @fetch_status=@@fetch_statuswhile @fetch_status=0
    begin
    update tb
    set type='a' where current of cur_Test fetch cur_Test
    select @fetch_status=@@fetch_status
    endclose cur_Test
    deallocate cur_Test
    go
      

  4.   

    请问楼上的朋友循环插入另一个表的存储过程怎么写?我不想一次全部插入,因为可能table1里有一些记录可能不满足条件需要循环比较过滤掉,所以需要循环一条一条插入,我不知道这个循环怎么写?麻烦教我,
    谢谢!
      

  5.   

    while exists(select 1 from tablename where ...)
    beginend
      

  6.   

    --不存在的
    while not exists(select 1 from tablename where ...)
    beginend