Solved

An INSERT EXEC statement cannot be nested.

Posted on 2010-11-26
2
859 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
Comment Utility
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
Comment Utility
thanks bibi
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

743 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

16 Experts available now in Live!

Get 1:1 Help Now