实现的条件:先看看有没的比60小的,有进入循环,在看有没比60小的,有就加2,当比97大的时跳出循环
declare @a int
select @a=chengj.textd from chengj where chengj.textd<60
declare @b int
select @b=chengj.textd from chengj where chengj.textd<97
while(@a<60)
begin
   while(@b<97)
    begin
  update chengj set textd=textd+2      end
breakend

解决方案 »

  1.   

    update chengj set textd=textd+2 
    where chengj.textd <60 直接一句更新就行了呀
      

  2.   

    while(exists(select 1 from chengj where chengj.textd <60)) 
    begin 
      while(exists(select 1 from chengj where chengj.textd <97)) 
        begin 
      update chengj set textd=textd+2 
        end 
    break 
    end 
      

  3.   

    declare @i int
    declare cur cursor for chengj.textd from chengj where chengj.textd <60  for update of textd
    open cur
    fetch cur into @I
    while (@@fetch_status = 0 )
    begin
        if @i < 60
            update chengj 
            set textd = textd +2
            where CURRENT OF cur
    if @i > 97 break
    fetch cur into @I
    end
    close cur
    deallocate cur
      

  4.   

    create table chengj(textd int)
    insert chengj select 40
    union all select 50while(exists(select 1 from chengj where chengj.textd <60)) 
    begin 
      while(not exists(select 1 from chengj where chengj.textd>97)) 
        begin 
        update chengj set textd=textd+2 
        end 
    break 
    endselect * from chengjdrop table chengj/**
    textd
    -----------
    88
    98(2 行受影响)
    **/
      

  5.   

    create table chengj(textd int)
    insert chengj select 40
    union all select 50declare @i int
    select @i = max(textd) from chengj where textd <60
    select @I = ceiling((97 - @i)*1.0/2)*2
    update chengj
    set textd = textd + @I
    where textd < 60select * from chengjdrop table chengj
    /*
    textd       
    ----------- 
    88
    98(所影响的行数为 2 行)
    */
      

  6.   


    这个太强了,while可以这么用啊