Solved

An INSERT EXEC statement cannot be nested

Posted on 2008-06-20
1
4,601 Views
Last Modified: 2012-05-05
When I try to capture the result set from sp_help_job using the following statement, it works fine:

INSERT dbname.dbo.tablename
EXEC [LinkedServer\Instance].msdb.dbo.sp_help_job @execution_status = 1
GO

If I try the following statement, it fails:

INSERT dbname.dbo.tablename
EXEC msdb.dbo.sp_help_job @execution_status = 1

with this error message:

Msg 8164, Level 16, State 1, Procedure sp_get_composite_job_info, Line 72
An INSERT EXEC statement cannot be nested.

I'm guessing that this is because sp_help_job calls sp_get_composite_job_info which has an INSERT...EXEC statement itself.  Why does this work for the linked server, in that case?  Is it something to do with the way the result set is returned?  How can the result set be captured on a local server?  I've tried setting up a linked server pointing back at itself but that doesn't work.

Thanks.  
0
Comment
Question by:mr_omid
[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
1 Comment
 

Accepted Solution

by:
mr_omid earned 0 total points
ID: 21847859
I found that this works:
INSERT dbo.TableName
SELECT * FROM OPENROWSET('sqloledb', 'server=servername;trusted_connection=yes', 'exec msdb.dbo.sp_help_job @execution_status=1')
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

728 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