?
Solved

An INSERT EXEC statement cannot be nested.

Posted on 2010-11-26
2
Medium Priority
?
913 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
[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 Comments
 
LVL 5

Accepted Solution

by:
adamsjs earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how the fundamental information of how to create a table.
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.

650 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