在数据库查询时知道怎么循环处理数据吗?

游标就可以做到。。。


declare @a varchar(50),@b varchar(50),@c varchar(50)                   ---这个不用解释都知道什么意思吧

---declare cursor1 cursor for         --定义游标cursor
--select  *  from  table1      字段可以根据自己的需要更改 可以是 select  a,b  from  table1     
declare cursor1 cursor for         --定义游标cursor1
select  *  from  table1              --使用游标的对象
open cursor1                       --打开游标1
fetch next from cursor1
into @a,@b,@c 
while @@fetch_status=0           --判断是否成功获取数据1
begin


--fetch next from cursor1 into @dutydate,@userid -- 将游标1向下移1行  记得下移,要不然会死循环

fetch next from cursor1 into @dutydate,@userid -- 将游标1向下移1行 
end
close cursor1                   --关闭游标1
deallocate cursor1

 

详见:http://www.itclw.net/forum.php?mod=viewthread&tid=45#lastpost

posted on 2011-11-06 00:36  wxm3177  阅读(181)  评论(0编辑  收藏  举报