Click here to Skip to main content
15,900,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I solve this error “An INSERT EXEC statement cannot be nested?”
My procedure is like.
SQL
CREATE PROCEDURE [dbo].[Procedure3]

   @para1 varchar(50),
   @para2 datetime
   
AS
BEGIN
CREATE TABLE #tem
(
 ….
 ….
)
insert into #tem (value) exec [dbo].[Procedure2] @para1,@para2,@para3
…….
…….
……….

END


And inside this stored procedure [dbo].[Procedure2] we have
SQL
CREATE PROCEDURE [dbo].[Procedure2]

   @para1 varchar(50),
   @para2 datetime,
   @para3 decimal(18,2)

AS
BEGIN
CREATE TABLE #temp
(
 Value decimal(18,2)
)
insert into #temp exec Procedure1 @para1,@para2,@para3
……..
…….
……..
select Name,Amount from #Temp1


END

Is it possible? If yes, then how?
Posted
Updated 4-Oct-11 0:20am
v3

1 solution

You are doing it wrong... If I am not wrong you are trying to insert the result of stored procedure into a temp table. You can achieve the same thing but in a different way...

Check out :
1. http://sqlserverplanet.com/sql/insert-stored-procedure-results-into-table/[^]
2. http://blog.coryfoy.com/2005/07/inserting-the-results-of-a-stored-procedure-to-a-temp-table/[^]
3. http://barry-king.com/2008/05/06/insert-into-temporary-table-from-stored-procedure/[^]
4. http://www.informit.com/articles/article.aspx?p=25288&seqNum=6[^]

Hope this helps.
All the best.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900