5

Hello I have a proc called Test_ProcA and I want to call Test_ProcB. I created a temp table called #temp with matching names and data types returned by Test_ProcB.

How do I insert the result set returned by Test_ProcB into #temp. When I try doing that I keep getting this error:

An INSERT EXEC statement cannot be nested.

Any ideas and suggestions on what needs to be done.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
SaiBand
  • 5,025
  • 15
  • 57
  • 76

3 Answers3

11

You're heading for a total maintenance nightmare. Here is an old article (which still receives updates) on the problem you're experiencing with some alternate ways to do the same thing.

http://www.sommarskog.se/share_data.html

djdanlib
  • 21,449
  • 1
  • 20
  • 29
4

when you create a SQL Server stored procedure you can have an INSERT INTO #TempTable from an other exec sp_xxx but you have to control that inside this second one there aren't similar techniques to manage data. You can have only "one level" and the "nested" ones cause the errors.

You'll have to extract the code and manage it inside the first level stored procedure, this is my approach.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
-1

This sentence works if you execute the SP from a linked server,

I think it's due to "Levels" mentioned by @Massimo Sedda

Regards!

StormeHawke
  • 5,987
  • 5
  • 45
  • 73
Ismael
  • 16
  • 1