When I try to capture the result set from sp_help_job using the following statement, it works fine:
EXEC [LinkedServer\Instance].msdb.dbo.sp_help_job @execution_status = 1
If I try the following statement, it fails:
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.