sql server2008游标 提示命令已成功生成

xiaoben9 2016-05-06 09:45:58
sql语句如下


declare test_cursor4 cursor scroll for
select StudyID
from [PACS].[dbo].MEDICAL_LOGON
open test_cursor4
DECLARE @examid int

WHILE @@fetch_status = 0
begin
fetch next from test_cursor4 into @examid
print @examid
end

close test_cursor4--关闭游标
deallocate test_cursor4--释放游标



游标运行第一次可以循环输出结果,


但是再次运行就只提示命令已成功生成,
(今天不知道为什么上传不了图片)

...全文
140 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
卖水果的net 版主 2016-05-06
  • 打赏
  • 举报
回复
while 之前,要先写一行     fetch next from test_cursor4 into @examid
xxfvba 2016-05-06
  • 打赏
  • 举报
回复
--不知道这样可不可以 declare test_cursor4 cursor scroll for select StudyID from [PACS].[dbo].MEDICAL_LOGON open test_cursor4 DECLARE @examid int fetch next from test_cursor4 into @examid WHILE @@fetch_status = 0 begin print @examid fetch next from test_cursor4 into @examid end close test_cursor4--关闭游标 deallocate test_cursor4--释放游标
xiaoben9 2016-05-06
  • 打赏
  • 举报
回复
引用 1 楼 xxfvba 的回复:
--不知道这样可不可以 declare test_cursor4 cursor scroll for select StudyID from [PACS].[dbo].MEDICAL_LOGON open test_cursor4 DECLARE @examid int fetch next from test_cursor4 into @examid WHILE @@fetch_status = 0 begin print @examid fetch next from test_cursor4 into @examid end close test_cursor4--关闭游标 deallocate test_cursor4--释放游标
谢谢,这样做事可以的
xiaoben9 2016-05-06
  • 打赏
  • 举报
回复
引用 2 楼 wmxcn2000 的回复:
while 之前,要先写一行     fetch next from test_cursor4 into @examid
谢谢,还真是这个原因

34,590

社区成员

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

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