Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Select" from Stored Procedures??

Status
Not open for further replies.

dBjason

Programmer
Joined
Mar 25, 2005
Messages
355
Location
US
SQL Server 7

I have a stored procedure that returns a recordset. Works great.

What I want to do is call that procedure from another stored procedure, and throw the data into a table. Something like:

Code:
CREATE PROC AS

SELECT Field1, Field2 INTO NewTable FROM MyStoredProc 'Parameter' ORDER BY Field2

--....Other Processing

I think I found a way to do it way back when, but forgot. Anyone have any ideas?

Thanks in advance,
Jason

 
Create a temp table that has the same structure as the data being returned from the sproc, then use insert exec.

Insert Into #TempTable
Exec MyStoredProc 'Parameter'

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
The simplest but not always practical way: create table in parent sproc, then do INSERT INTO table EXEC sproc.



------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
Awesome! Thanks Denis & George!!
 
Note that if you want temporary processing you must use a #temp table not a table varaible. YOu cannot insert the results of a stored proc into a table variable. Anybody know if this changed in 2005 version?

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
I just tried a Select INTO a table var and it didn't work, I assume the same for SPs

Jim
 
Scratch that.. in 2005 I did:
Code:
DECLARE @t table(resposnetypeid int)
insert into  @t
exec test

and it worked...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top