T-SQL游标使用模板

declare 
@id int,
@
--声明变量
declare Response cursor
for SELECT 
 
  FROM [InventionToolOldEffect].[dbo].[avibg] WHERE     (是否效应 = 1)
ORDER BY 效应编号
--声明游标
open Response --打开游标
fetch next from Response
into
@id,
@
--将第一行游标内容存储在变量
while @@fetch_Status=0 --游标循环开始
begin

 
Print @id
-- 这里放游标内容
fetch next from Response into
@id,
@
--将游标移动到下一行
end --游标循环结束
close Response --关闭游标
deallocate Response -- 释放游标
posted @ 2008-05-15 22:00  湘西小刁民  阅读(229)  评论(0编辑  收藏  举报