【问题标题】:Putting Result sets into a temp table将结果集放入临时表
【发布时间】:2011-10-07 17:47:39
【问题描述】:

我有一个名为 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.

谁能帮帮我。

【问题讨论】:

  • 你到底为什么要把你的过程命名为INSERT
  • 为什么你没有做正确的事情并编写插入而不是使用一般的插入过程?

标签: sql-server sql-server-2008 stored-procedures resultset


【解决方案1】:

An INSERT EXEC statement cannot be nested. 错误信息很清楚。您正在嵌套 INSERT ... EXEC。陈述。您调用的过程 (Generate_Insert) 再次使用 INSERT ... EXEC 或 insert 过程的调用者在 INSERT ... EXEC 中使用它。只有你能找到是哪种情况。根据经验,应该避免 INSERT ... EXEC,因为 this and other problems

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    • 2011-07-08
    • 2015-11-12
    • 2014-10-26
    • 1970-01-01
    相关资源
    最近更新 更多