将结果集放入临时表中
我有一个名为 Insert 的过程,代码如下所示:
Create procedure Gen_insert
As
BEGIN
create table #temp
( insert_stmt varchar(max) )
insert into #temp
EXEC Generate_Insert @Table = 'Admin'
insert into #temp
EXEC Generate_Insert @Table = 'Impas'
insert into #temp
EXEC Generate_Insert @Table = 'Asui'
insert into #temp
EXEC Generate_Insert @Table = 'Alstd'
select * from #temp
End
当我执行它时,出现以下错误:
Msg 8164, Level 16, State 1, Procedure Gen_Insert, Line 73
An INSERT EXEC statement cannot be nested.
任何人都可以帮助我。
I have a procedure called Insert and the code looks like:
Create procedure Gen_insert
As
BEGIN
create table #temp
( insert_stmt varchar(max) )
insert into #temp
EXEC Generate_Insert @Table = 'Admin'
insert into #temp
EXEC Generate_Insert @Table = 'Impas'
insert into #temp
EXEC Generate_Insert @Table = 'Asui'
insert into #temp
EXEC Generate_Insert @Table = 'Alstd'
select * from #temp
End
When I execute it I am getting following error:
Msg 8164, Level 16, State 1, Procedure Gen_Insert, Line 73
An INSERT EXEC statement cannot be nested.
Can anyone help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
INSERT EXEC 语句不能嵌套。
错误消息非常清楚。您正在嵌套 INSERT ... EXEC。声明。您调用的过程 (Generate_Insert
) 再次使用 INSERT ... EXEC,或者insert
过程的调用者在 INSERT ... EXEC 中使用它。只有您才能找到具体情况。根据经验,应避免 INSERT ... EXEC,因为这个问题和其他问题。An INSERT EXEC statement cannot be nested.
The error message is quite clear. You are nesting INSERT ... EXEC. statements. Either the procedures you call (Generate_Insert
) use again INSERT ... EXEC or the caller ofinsert
procedure uses it in an INSERT ... EXEC. Only you can find which is the case. As a rule of thumb, INSERT ... EXEC should be avoided, because of this and other problems.