Solved

An INSERT EXEC statement cannot be nested.

Posted on 2010-11-26
2
869 Views
Last Modified: 2012-05-10
Hello,

I have this error An INSERT EXEC statement cannot be nested. when I try this :
declare @sql2 nvarchar(max)
set @sql2 = 'sp_scriptpublicationcustomprocs  ['test'] '
INSERT INTO repl_transac_sp execute (@sql2)
print @sql2
How can I resolve this problem?

Thanks

bibi
0
Comment
Question by:bibi92
2 Comments
 
LVL 5

Accepted Solution

by:
adamsjs earned 500 total points
ID: 34220908
You didn't indicate what error you are receiving, but is it this?:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'test'.

Open in new window


It appears you want to specify a parameter value of 'test' for the sp_scriptpublicationcustomprocs procedure?  If so, this should work for you:

DECLARE @sql2 nvarchar(max)
SET @sql2 = 'sp_scriptpublicationcustomprocs  ''test'' '
INSERT INTO repl_transac_sp EXECUTE (@sql2)
PRINT @sql2

Open in new window


Since your parameter value is part of the string to which you are setting the value of @sql2, you need to double-up the single quotes inside the string.  The brackets are not called for in this case.
0
 

Author Closing Comment

by:bibi92
ID: 34221162
thanks bibi
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now