Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Replication (2008)
 An INSERT EXEC statement cannot be nested.

Author  Topic 

mydeath4u
Starting Member

3 Posts

Posted - 2011-12-23 : 04:09:08
I am trying to insert the publication status into a temporary table as below


insert into #pub_status
exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE'


but am getting the below error


Msg 8164, Level 16, State 1, Procedure sp_MSload_tmp_replication_status, Line 80

An INSERT EXEC statement cannot be nested.


In SQL Server 2005, this issue is resolved by executing the statment before inserting into temp table like below


exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE'

insert into #pub_status
exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE'



But this work around is not helping in SQL server 2008.

Please help in solving this ASAP.



San...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-23 : 04:15:23
try using below syntax instead


insert into #pub_status
select *
from openrowset('SQLNCLI','Server=Servername;Trusted_Connection=yes;','exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE') AS a


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-12-23 : 05:03:20
Since you know the no of columns the sp would return then you can create the table with the columns instead of insert into...and then insert into the table from the stored proc.


PBUH

Go to Top of Page

mydeath4u
Starting Member

3 Posts

Posted - 2011-12-23 : 07:32:35
Sachin,

I did not understand your solution. Currently am creating a temporary table and then am inserting into it.

quote:
Originally posted by Sachin.Nand

Since you know the no of columns the sp would return then you can create the table with the columns instead of insert into...and then insert into the table from the stored proc.


PBUH





San...
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-12-23 : 13:26:24
I am saying create a temporary table with a create statement and define the columns and then use the insert statement to insert data from the sp.
If my sp returns only single column say id then do Something like this

Create table #t(id int)

Insert into #t
Exec MySp



PBUH

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-23 : 23:42:55
quote:
Originally posted by Sachin.Nand

I am saying create a temporary table with a create statement and define the columns and then use the insert statement to insert data from the sp.
If my sp returns only single column say id then do Something like this

Create table #t(id int)

Insert into #t
Exec MySp

sorry but i cant see how this will solve the problem

you're still doing insert...exec which is cause for problem OP is facing


PBUH





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-12-24 : 01:39:09
Sorry..Not sure what I was thinking...

PBUH

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-24 : 02:48:49
quote:
Originally posted by Sachin.Nand

Sorry..Not sure what I was thinking...

PBUH




No problem
happens for all

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mydeath4u
Starting Member

3 Posts

Posted - 2011-12-30 : 10:10:15
This solution worked Visakh. Just added something as below


insert into #pub_status
select *
from openrowset('SQLNCLI','Server=Servername;Trusted_Connection=yes;','SET FMTONLY OFF exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE') AS a


Thank you Visakh

quote:
Originally posted by visakh16

try using below syntax instead


insert into #pub_status
select *
from openrowset('SQLNCLI','Server=Servername;Trusted_Connection=yes;','exec distribution..sp_replmonitorhelppublication @@SERVERNAME,'DATA_BASE') AS a


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





San...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-01 : 02:34:45
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -