实现的条件:先看看有没的比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
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
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
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
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 行受影响)
**/
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 行)
*/
这个太强了,while可以这么用啊