SQL编程怎样遍历查询结果?

Philip1314 2001-12-13 03:11:36
大概象这样吧
declare @num int
select number from table1 where number > 100
然后将查询结果循环赋值给 @num 变量
...全文
218 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Philip1314 2001-12-13
  • 打赏
  • 举报
回复
多谢
王集鹄 2001-12-13
  • 打赏
  • 举报
回复
DECLARE authors_cursor CURSOR
FOR SELECT * FROM authors
OPEN authors_cursor
FETCH NEXT FROM authors_cursor

N_chow 2001-12-13
  • 打赏
  • 举报
回复
動用Cursor.
Declare abc CURSOR FOR Select number from table1 where number>100
open abc
Fetch next from abc into @num
WHILE @@Fetch_status=0
begin
Print @num
Fetch next from abc into @num
end
close abc
deallocate abc

34,623

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧