您的位置:首页 > 其它

游标使用示例

2010-01-06 09:52 405 查看
declare @id nvarchar(20) --定义变量来保存ID号
declare @A float --定义变量来保存值
declare mycursor cursor for select * from tb_c --为所获得的数据集指定游标
open mycursor --打开游标
fetch next from mycursor into @id,@A --开始抓第一条数据
while(@@fetch_status=0) --如果数据集里一直有数据
begin
select tb_b.name,(tb_b.gz + @A) from tb_b where tb_b.id = @id --开始做想做的事(什么更新呀,删除呀)
fetch next from mycursor into @id,@A --跳到下一条数据
end
close mycursor --关闭游标
deallocate mycursor --删除游标

本文来源于Woody的鸟窝(Woody's Blog) http://www.smartgz.com, 原文地址:http://www.smartgz.com/blog/Article/976.asp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: