我知道不可能嵌套 insert ... exec
语句,但我仍然感兴趣 - 有没有办法检查我是否已经有事件的 insert .. .exec
以避免实际错误?
所以我想要这样的东西:
....
if <check if I have outer insert into exec> = 0
insert into <#some temporary table>
exec <stored procedure>
换句话说 - insert ... exec
是可选的,拥有它很好,但如果有人尝试使用外部 insert ... 调用我的过程,我想跳过它执行
最佳答案
如上所述here
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.
尝试使用OpenRowset
INSERT INTO #YOUR_TEMP_TABLE
SELECT * FROM OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','set fmtonly off EXEC [ServerName].dbo.[StoredProcedureName] 1,2,3')
关于sql - 避免 "An INSERT EXEC statement cannot be nested",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35010612/