游标变量找不到了??

smalldeer 2003-11-28 11:58:11
在游标循环期间执行存储过程

Declare @dav as varchar(100)
Declare cursor5 cursor for select title from title
open cursor5
fetch cursor5 into @dav
while @@fetch_status=0
begin
set @sql='.....'
exec sp_executesql @sql --执行一个存储过程
fetch cursor5 into @dav
end
close cursor5 ---关闭游标
Deallocate Cursor5 ---删掉游标


报错
@dav变量未定义


...全文
58 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
smalldeer 2003-11-28
  • 打赏
  • 举报
回复
还是报错??
tangxc2003 2003-11-28
  • 打赏
  • 举报
回复
Declare @dav as varchar(100)
Declare cursor5 cursor for select title from title
open cursor5
fetch next from cursor5 into @dav
while @@fetch_status=0
begin
set @sql='.....'
exec sp_executesql @sql
fetch next from cursor5 into @dav
end
close cursor5
Deallocate Cursor5
shuiniu 2003-11-28
  • 打赏
  • 举报
回复
代码没问题呀!
kseven 2003-11-28
  • 打赏
  • 举报
回复

Declare @dav as varchar(100)
Declare cursor5 cursor for select a from c
open cursor5

while @@fetch_status=0
begin
fetch next from cursor5 into @dav
set @sql=' '
exec sp_executesql @sql --执行一个存储过程
end
close cursor5 ---关闭游标
Deallocate Cursor5 ---删掉游标
smalldeer 2003-11-28
  • 打赏
  • 举报
回复
谢谢大力

我的过失

谢谢
txlicenhe 2003-11-28
  • 打赏
  • 举报
回复
请楼主出示全部代码
pengdali 2003-11-28
  • 打赏
  • 举报
回复
set @sql='exec 过程名 '''+@dav+''''
exec sp_executesql @sql
pengdali 2003-11-28
  • 打赏
  • 举报
回复
你出错得地方在

set @sql='.....'
exec sp_executesql @sql --执行一个存储过程

这里面
shuiniu 2003-11-28
  • 打赏
  • 举报
回复
把这句先注释掉exec sp_executesql @sql !
看看报不报错!!

34,874

社区成员

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

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