Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insertion into temp table problem.

Author  Topic 

akarra
Starting Member

15 Posts

Posted - 2010-02-01 : 09:24:39
when trying to execute a procedure iam getting the below error

An INSERT EXEC statement cannot be nested. [SQLSTATE 42000] (Error 8164). The step failed.

Iam trying to insert data into a temporary table as follows
(the temp table is the exact copy of the sp_help_job table structure.)

INSERT #jobs_status EXEC msdb.dbo.sp_help_job

what could be the problem.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 09:29:02
i think you're calling the main sp somewhere in insert exec so that its getting nested
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-02-01 : 10:48:49
You've hit upon a restriction - good article to reference is : http://www.sommarskog.se/share_data.html

Jack Vamvas
--------------------
http://www.ITjobfeed.com
Go to Top of Page

Kanwulf
Starting Member

11 Posts

Posted - 2010-02-01 : 10:57:15
The problem is that sp_help_job calls sp_get_composite_job_info stored procedure. And sp_get_composite_job_info has several INSERT EXEC statements in its code so this is where the nesting comes from.

To work you could use OPENQUERY like this:

exec sp_serveroption 'MyServerName', 'data access', 'true'
select * INTO #jobs_status FROM OPENQUERY( MyServerName, ' EXEC msdb.dbo.sp_help_job ')

Go to Top of Page

akarra
Starting Member

15 Posts

Posted - 2010-02-01 : 14:13:26
Yes it has worked. Thanks very much Kanwulf.
Go to Top of Page
   

- Advertisement -