Solved

An INSERT EXEC statement cannot be nested.

Posted on 2010-11-26
2
879 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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 the fundamental information of how to create a table.

831 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