Solved

Insert Exec cannot be nested

Posted on 2013-01-23
4
603 Views
Last Modified: 2013-01-25
I had the following statement in my stored procedure

INSERT INTO #nextMtg EXECUTE proc_nextMtgList @estID,'', 0

I got the error 'Insert Exec cannot be nested...' and I realised there is another INSERT INTO..EXECUTE stmt in the same store procedure. So I changed my line of code to

INSERT INTO #upcomMtg
Select * from openrowset('SQLOLEDB','Server=<instance\servername>;UID=<uid>;PWD=<pwd>;database=<dbname>;Trusted_Connection=yes;','EXEC <dbname>.dbo.proc_nextMtgList 526,'''', 0') AS a

Now I am getting the error 'Invalid object name #rvmyMtg'
#rvmyMtg is a temp table created in the stored procedure proc_nextMtgList.

The stored procedure proc_nextMtgList is working correctly by itself. What could be causing the invalid object error?
0
Comment
Question by:Angel02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 300 total points
ID: 38811842
TEMP tables like #rvmyMtg have a scope limited to the current connection (I believe).  But openrowset creates a new connection, so the temp table is out of scope there.
0
 

Author Comment

by:Angel02
ID: 38812021
So what wrong am I doing here?
0
 
LVL 40

Expert Comment

by:lcohan
ID: 38812062
Actually you can...there is a trick with dynamic SQL and sp_executesql and OPENROWSET - let me find an example...

check this and look for the OPENROWSET:

http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/e66c9e71-4424-4cf3-920c-6725ffc40162/

or this similar:

http://blogs.technet.com/b/wardpond/archive/2005/08/01/408502.aspx
0
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 200 total points
ID: 38812114
my bad...sorry - knightEknight is right and I just noticed now that you run the SQL Code on one Server but ....#rvmyMtg is created by a stored proc running on another server so that temp table IS in that server tempDB and not in tempdb where you run the code. Would be easier to use permanent working table so you can fully qualify them and eventualy linked servers instead.

"Now I am getting the error 'Invalid object name #rvmyMtg'
#rvmyMtg is a temp table created in the stored procedure proc_nextMtgList."
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question