exec中执行多条语句的问题

proud 2008-08-19 08:40:42
比如:
exec('select * from table1')
exec('select * from table2')
exec('select * from table3')
想在一条exec中完成
也就是:
exec('select * from table1' + 'select * from table2' + 'select * from table3')
可是执行不了,请问怎么解决?
...全文
262 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuangdp 2008-08-19
  • 打赏
  • 举报
回复
[Quote=引用楼主 proud 的帖子:]
比如:
exec('select * from table1')
exec('select * from table2')
exec('select * from table3')
想在一条exec中完成
也就是:
exec('select * from table1' + 'select * from table2' + 'select * from table2' )
可是执行不了,请问怎么解决?
[/Quote]

写的太紧了,你这样成了 select * from table1select * from table2select * from table2

肯定报错啊 加空格或者;什么的都可以执行
  • 打赏
  • 举报
回复
declare @s varchar(8000)
set @s='select * from tb;select * from tb1;select * from tb2'
exec (@s)
mugua604 2008-08-19
  • 打赏
  • 举报
回复
可以啊!!
exec('select * from table1 select * from table2 select * from table3')

22,209

社区成员

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

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