问:


I have three stored procedures Sp1, Sp2 and Sp3.
The first one (Sp1) will execute the second one (Sp2) and save returned data into #tempTB1 and the second one will execute the third one (Sp3) and save data into #tempTB2.
If I execute the Sp2 it will work and it will return me all my data from the Sp3, but the problem is in the Sp1, when I execute it it will display this error:

INSERT EXEC statement cannot be nested

I tried to change the place of execute Sp2 and it display me another error:

Cannot use the ROLLBACK statement within an INSERT-EXEC statement.

SQL脚本如下:

Create Procedure Sp3
As
Begin
Select 'Arun' Name, 'Pollachi' Place
Union
Select 'Vedaraj' Name, 'Devakottai' Place
End
Go Create Procedure Sp2
As
Begin
Create Table #tempTB2
(
Name Varchar(50), Place Varchar(50)
)
INSERT #tempTB2
Exec Sp3
SELECT 'Sp2' [Source], * FROM #tempTB2 DROP TABLE #tempTB2
End
Go Create Procedure Sp1
As
Begin
Create Table #tempTB1
(
[Source] Varchar(50), Name Varchar(50), Place Varchar(50)
) INSERT #tempTB1
Exec Sp2 select * from #tempTB1 DROP TABLE #tempTB1
End
Go Exec Sp1;--报错:An INSERT EXEC statement cannot be nested.

答:


This is a common issue when attempting to 'bubble' up data from a chain of stored procedures. A restriction in SQL Server is you can only have one INSERT-EXEC active at a time. I recommend looking at How to Share Data Between Stored Procedures which is a very thorough article on patterns to work around this type of problem.
For example a work around could be to turn Sp3 into a Table-valued function.

原文链接

SQL Server中INSERT EXEC语句不能嵌套使用(转载)的更多相关文章

  1. SQL Server误区30日谈 第26天 SQL Server中存在真正的“事务嵌套”

    误区 #26: SQL Server中存在真正的“事务嵌套”错误 嵌套事务可不会像其语法表现的那样看起来允许事务嵌套.我真不知道为什么有人会这样写代码,我唯一能够想到的就是某个哥们对SQL Serve ...

  2. SQL Server中的流控制语句

    begin···end 该语句定义sql代码块,通常在if和while语句中使用 declare @num int ; ; begin ; print 'hello word' end if···el ...

  3. SQL Server中使用convert进行日期转换(转载)

    一般存入数据库中的时间格式为yyyy-mm-dd hh:mm:ss 如果要转换为yyyy-mm-dd  短日期格式.可以使用convert函数.下面是sqlserver帮助中关于convert函数的声 ...

  4. Sql server中内连接语句

    数据库中学生表和课程表如下: 内连接sql语句: select a.studentName,a.studentAge,b.courseName from student a inner join co ...

  5. SQL server中的T-SQL语句

    首先点击新建查询 如下图所示 创建数据库:create database 数据库名称 使用数据库:use 数据库名称 创建表:create table 表名 ( 代码 ) 输入完成执行时需选中 如果需 ...

  6. sql server 中使用 LIKE 语句 SqlParameter 使用

    原本写的 select * from table where name like  '%@searchStr%' 怎么执行都不对,想想 参数是不能加 引号的 于是改为select * from tab ...

  7. sql server中游标

    参考:http://blog.csdn.net/luminji/article/details/5130004 利用SQL Server游标修改数据库中的数据 SQL Server中的UPDATE语句 ...

  8. SQL Server中【case...end】的用法

    在SQL Server中 case...end 语句,一般有如下两种用法: 1.相当于C#中if...else,例: select CName,头衔=case when CLevel='A1' the ...

  9. SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别

    SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别 MSSQL为我们提供了两种动态执行SQL语句的命令,分别是 EXEC 和 SP_EXECUTESQL ,我们先来看一下两种方 ...

随机推荐

  1. go-运算符

    算术运算符 ++,--只能放在变量后面,不能放在前面 独立使用 目的:更简洁 go语言不支持三元运算符 键盘输入 fmt.scanln 会在换行时扫描,所以最后一个条目必须换行或达到结束位置 fmt. ...

  2. JS实现深浅拷贝

    1.实现浅拷贝 // 1. ...实现 let copy1 = {...{x:1}} // 2. Object.assign实现 let copy2 = Object.assign({}, {x:1} ...

  3. ESP8266与ESP8285开发时有什么区别

    ESP8266模块在WiFi联网领域已经被广泛使用,但是ESP8266芯片是需要外挂Flash芯片的,这样就使模块不能做的更小.之后乐鑫公司又推出了ESP8285芯片,直接集成了1MByte的Flas ...

  4. Mixins and Python

    什么是Mixin (混入) Mixin 这个词在Python/Ruby中经常使用, Java 中几乎看不到这个名词. 在Java 中, 我们经常定一个一个子类扩展了某个基类, 同时实现某些接口. 因为 ...

  5. Fundebug录屏插件更新至0.6.0

    摘要: 录屏插件的性能进一步优化,传输的数据体积大幅度减少. 录屏功能介绍 Fundebug提供专业的异常监控服务,当线上应用出现 BUG 的时候,我们可以第一时间报警,帮助开发者及时发现 BUG,提 ...

  6. mssql sqlserver if exists 用法大汇总

    摘要: 下文讲述sqlserver中,更新脚本中常用if exists关键字的用法说明,如下所示: 实验环境:sql server 2008 R2 一.检测数据库是否存在于当前数据库引擎下 if ex ...

  7. [视频教程]利用SSH隧道进行远程腾讯云服务器项目xdebug调试

    我的远程服务器是腾讯云的ubuntu系统机器,本地我的电脑系统是deepin的系统,使用的IDE是vscode.现在就来使用本地的IDE来调试腾讯云中为网站项目实现逻辑是访问网站域名后,请求被转发给腾 ...

  8. windows防火墙失效

    在某些情况下,我们希望阻止某款软件联网,比如防止软件更新. 通常来说使用windows自带的防火墙是可以阻止软件联网的,但在我的电脑上它却失效了,无法起到阻止软件联网的作用. 我的操作系统: OS 名 ...

  9. MD文件图片base64自动编码

    看工具链接请直接将文章拉到最后.. 概述 不知道你在使用markdown写文章的时候有没有遇到过这样的烦恼, 文件写完了, 想将写完的文章粘贴到博客的时候, 你满心欢喜的复制粘贴, 但是发现图片根本复 ...

  10. 浮点型数据需要转化为int,才能作为点,被读取abc = np.array(abc, dtype=np.int)

    import cv2 import numpy as np import matplotlib.pyplot as plt img = 'test.jpg' img = cv2.imread(img) ...