首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有关创建游标以循环记录的SQL Server 2008请求示例

有关创建游标以循环记录的SQL Server 2008请求示例
EN

Stack Overflow用户
提问于 2012-08-08 09:41:27
回答 1查看 39.1K关注 0票数 17

有没有创建游标来循环遍历一堆记录的经验?如果你有,你能给我提供一个基本的例子吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-08-08 11:11:54

代码语言:javascript
复制
declare cur cursor for 
select id from tbl 
open cur
declare @id int
fetch next from cur into @id
while (@@FETCH_STATUS = 0)
begin
    print(@id)
    fetch next from cur into @id
end
close cur
deallocate cur

-- just replace "tbl" with your table name and "id" with your field name
-- and do whatever you want in begin-end block (now it simply prints the id of each record)
票数 27
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11856518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档