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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting a stored procedure directly into a temp table?

Status
Not open for further replies.

tokuzumi

Programmer
Sep 16, 2002
40
0
0
US
I want to insert the results of a stored procedure directly into a temp table. Is there a way to do that without first declaring the temp table? Using TSQL, you can do it like this;

select field1, field2, field3
into #table
from tablename

If I try to do this:
exec storedprocname param1, param2
into #table

I get "Incorrect syntax near keyword 'into'"

I would rather save some code, and not declare the tables, if I don't have to. Any ideas? Thanks in advance.
 
Try
insert into #table exec storedprocname param1, param2


but your stored procedure should do only select statement
 
Here is what I ended up doing:

I created a UDF, that returns a table, that returns the same recordset as the stored procedure I was trying to execute. Then I used the following syntax;

select * into #table from dbo.udfname(param1,param2)

Using that methodology, it works like a champ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top