I need to access the results of a stored procedure in a temp table which would normally be done using INSERT/EXEC. My problem is that the stored procedure already uses INSERT/EXEC and nesting of this method is not allowed.
Having searched around the this forum I am thinking that the simplest solution might be to define the temp table for the called stored procedure from the calling stored procedure then call the latter. The lower level stored procedure is quite complex (unlike the example below) so I am considering the use of an optional input parameter in the called store procedure to control where the creation of the temp table occurs so that existing code and reports that use this stored will still work.
Any comments on whether this would be a useful solution would be appreciated.
SP Test1 is just to provide something for SP Test2 to call.
In real life SP Test2 is quite complex and I wouldn't want to create another copy of it, hence the use of a new optional parameter to allow existing calls to work as they do now.
SP test3 would actually process the rows in #Temp2 not simply select * from #Temp2 as shown in this example.
create procedure Test1 as select TagName into #temp1 from Tags select * from #temp1
create procedure Test2 (@CreateTempTable int = 1) as if @CreateTempTable = 1 create table #Temp2 (TagName varchar(150)) insert #Temp2 exec Test1 if @CreateTempTable = 1 select * from #Temp2
create procedure Test3 as create table #Temp2 (TagName varchar(150)) exec Test2 0 select * from #Temp2
R Campbell