Solved

An INSERT EXEC statement cannot be nested.

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Job Hung 17 37
sql query 5 44
add stored proc on publlication 4 20
SQL Query Returns Records in SSMS but not Classic ASP 5 25
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

733 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