Link to home
Start Free TrialLog in
Avatar of mr_omid
mr_omid

asked on

An INSERT EXEC statement cannot be nested

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.  
ASKER CERTIFIED SOLUTION
Avatar of mr_omid
mr_omid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial