gpt4 book ai didi

sql - INSERT EXEC 语句不能嵌套。处理错误

转载 作者:行者123 更新时间:2023-12-03 18:33:05 25 4
gpt4 key购买 nike

不重复。这里的问题是它有不同的结构。我对可以更改的内容和不能更改的内容有一些限制。在这里我有确切的例子,其他门票没有。 OPENROWSET 也不能应用,因为 test1 循环遍历所有数据库(使用 EXEC sp_MSforeachdb @sql)。而且我不能使用它,因为在 OPENROWSET 中你必须指定你从哪个数据库运行程序

假设我有这两个 SP:

create procedure test1
@ProcName varchar(155)
as
begin

if OBJECT_ID('tempdb..#testt') is not null drop table #testt
create table #testt1(a int, b int)

insert #testt1
exec @ProcName

select * from #testt1
end

create procedure test2
as
begin

declare @sql varchar(155)

if OBJECT_ID('tempdb..#testt2') is not null drop table #testt2
create table #testt2(a int, b int)

select @sql = 'select 1 as a,2 as b'

insert #testt2
exec (@sql)

select * from #testt2

end

当我运行 exec test1 @ProcName = 'Test2' 时,它返回错误:

An INSERT EXEC statement cannot be nested.

这里的问题是我无法停止在test2 中使用insert exec。 test1 应该有@ProcName 作为变量

解决此问题最轻松的方法是什么?

最佳答案

insert 语句放入 test2 过程解决了问题

关于sql - INSERT EXEC 语句不能嵌套。处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44051283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com