为什么会执行多次

ylm2003 2014-05-26 09:20:02
declare @num int
set @num=1
declare cpy cursor for select name from sysobjects where xType= 'U' and category=0
open cpy
declare @oldname varchar(20)
declare @sql varchar(1000)
fetch from cpy into @oldname
while @@FETCH_STATUS=0
begin
set @sql='select top 0 * into '+ @oldname+'_'+convert(varchar(10),@num) +' from '+ @oldname
exec (@sql)
fetch from cpy into @oldname
end
close cpy
deallocate cpy
...全文
94 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
發糞塗牆 2014-05-27
  • 打赏
  • 举报
回复
exec (@sql)改成print @sql,看看执行了些什么
haitao 2014-05-26
  • 打赏
  • 举报
回复
执行前, select name from sysobjects where xType= 'U' and category=0 的结果是多少条 执行后, select name from sysobjects where xType= 'U' and category=0 的结果是多少条

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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