An INSERT EXEC statement cannot be nested
I ran into the following problem: if a procedure is using INSERT EXEC, and you try to INSERT EXEC that procedure, you get the following error message:
An INSERT EXEC statement cannot be nested.
Example:
USE MyDBGOCREATE PROC dbo.Proc1ASSELECT 1GOCREATE PROC dbo.Proc2ASSET NOCOUNT ONCREATE TABLE #t (value INT)INSERT INTO #tEXEC Proc1SELECT * FROM #tGOCREATE TABLE #results (value INT)INSERT INTO #resultsEXEC dbo.Proc2An INSERT EXEC statement cannot be nested.
I found the following simple workaround:
INSERT INTO #resultsSELECT * FROM OPENROWSET('SQLNCLI', 'server=(local);trusted_connection=yes', 'EXEC MyDB.dbo.Proc2')
