An INSERT EXEC statement cannot be nested.在线等

lingjin520 2010-09-27 06:58:37
CREATE TABLE #test(colAssetID int not NULL)
INSERT INTO #test
EXEC B_Create 145, 'Name_T', 'Test',2

Error: An INSERT EXEC statement cannot be nested
B_Create 是个返回SELECT 结果的存储过程,不是return返回,也不是output返回,他会返回一行一列的一个值.我之前用过上面的方法得到SELECT结果,但用在这个比较复杂的B_Create上会就有上面的错误,请问有什么别的方法得到SELECT的返回值吗?

在线等答案,马上给分
...全文
209 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lingjin520 2010-09-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 sqlcenter 的回复:]
引用楼主 lingjin520 的回复:
Error: An INSERT EXEC statement cannot be nested


这个错误提示还不够明白吗?INSERT EXEC 不能嵌套

说明: 存储过程 B_Create 返回的结果集,也是通过 insert exec 另一个存储过程 生成的

这种嵌套是不允许的
[/Quote]我不是不明白原因,我是问有什么方法可以解决....
lingjin520 2010-09-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 abuying 的回复:]
LZ为何把insert into写入存储过程中。
你的存储过程有问题。
[/Quote]晕,SP有insert to就是有问题!!
lingjin520 2010-09-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ws_hgo 的回复:]
人了
快点
我要回家啦
[/Quote]这个存储过程不能发啊,会违反规定的,里面是有insert操作
abuying 2010-09-27
  • 打赏
  • 举报
回复
LZ为何把insert into写入存储过程中。
你的存储过程有问题。
SQLCenter 2010-09-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 lingjin520 的回复:]
Error: An INSERT EXEC statement cannot be nested
[/Quote]

这个错误提示还不够明白吗?INSERT EXEC 不能嵌套

说明: 存储过程 B_Create 返回的结果集,也是通过 insert exec 另一个存储过程 生成的

这种嵌套是不允许的
「已注销」 2010-09-27
  • 打赏
  • 举报
回复
Error: An INSERT EXEC statement cannot be nested

==================
晕倒,你存储过程嵌套了,出现问题,修改存储过程。
「已注销」 2010-09-27
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ai_li7758521 的回复:]

SQL code

alter proc B_Create
(
@i int,
@o nvarchar(20),
@p nvarchar(20),
@q int
)
as
begin
EXEC('select 1 union all select 2')
end


CREATE TABLE #test(colAssetID int not NULL)
……
[/Quote]
嗯,可能是存储过程问题
ai_li7758521 2010-09-27
  • 打赏
  • 举报
回复

alter proc B_Create
(
@i int,
@o nvarchar(20),
@p nvarchar(20),
@q int
)
as
begin
EXEC('select 1 union all select 2')
end


CREATE TABLE #test(colAssetID int not NULL)
INSERT into #test
EXEC B_Create 145, 'Name_T', 'Test',2


select * from #test

/*
colAssetID
-----------
1
2

(2 行受影响)

*/


drop table #test
可能是你存储过程的问题
dawugui 2010-09-27
  • 打赏
  • 举报
回复
EXEC B_Create 145, 'Name_T', 'Test',2
这个结果是什么?是否满足你那个临时表?
「已注销」 2010-09-27
  • 打赏
  • 举报
回复
如果返回正确是没有问题的
我测试通过

CREATE TABLE kk(a INT ,b DECIMAL(10) ) --
INSERT INTO kk
exec dbo.PROC_StaticNeedMaterial 43493

fldID fldProductCode fldMaterialCode fldNeedQuantity fldLostQuantity
-------------------- --------------- --------------- --------------------------------------- ---------------------------------------
1 P101 15772 10.00000000 2.00000000
3 P102 15772 15.00000000 3.00000000
4 P103 3748 12.00000000 4.00000000
5 P104 48926 13.00000000 2.00000000
6 P105 48926 12.00000000 2.00000000
7 P106 48926 24.00000000 5.00000000
938 43493 10035 10.00000000 0.05000000
939 43493 10042 23.00000000 0.11500000
940 43493 10050 5.00000000 0.05000000
941 43493 10052 1.00000000 0.00500000

(10 row(s) affected)
ai_li7758521 2010-09-27
  • 打赏
  • 举报
回复
create proc B_Create
(
@i int,
@o nvarchar(20),
@p nvarchar(20),
@q int
)
as
begin
select 1
end


CREATE TABLE #test(colAssetID int not NULL)
INSERT into #test
EXEC B_Create 145, 'Name_T', 'Test',2


select * from #test

/*
colAssetID
-----------
1
*/


drop table #test
没有问题啊
ws_hgo 2010-09-27
  • 打赏
  • 举报
回复
人了
快点
我要回家啦
gw6328 2010-09-27
  • 打赏
  • 举报
回复

use dbx
go


create procedure up_t
as
begin
select 1 union all
select 2 union all
select 3 union all
select 4
end

go

create table #t
(
id int primary key identity(1,1)
,c int
)
go

insert into #t exec up_t

select * from #t

drop table #t
ws_hgo 2010-09-27
  • 打赏
  • 举报
回复
B_Create

存储过程发出来看看
gw6328 2010-09-27
  • 打赏
  • 举报
回复
要看你B_Create返回的是不是合符的集合。

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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