When trying to insert a stored procedure into a temporary table, getting "the name or name of an object or column is missing or empty"

Possible duplicate: How to select * INTO [temp table] FROM [Stored procedure]

I am new to T-SQL . I have a stored procedure that selects records. I want to query the records returned by the stored procedure, so I'm trying to insert records into a temporary table. (Stack Overflow Messages and other messages say this is how to do it.)

But when I try, I get an error:

Missing or empty object or column name '

When I just start the stored procedure, I get a table with columns with names.

select * into #temp1 exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp' //throws error saying columns must have names 

but

 exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp' // Returns cols with names 

What am I missing?

+7
source share
1 answer

First try creating a temporary table:

 CREATE TABLE #temp1 ( COL1 INT, COL2 VARCHAR(MAX) ) INSERT INTO #temp1 exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp' 

For an extremely wide range of results, you can use OPENROWSET

In any case, this SO has many options: Insert the results of the stored procedure into a temporary table

+6
source

All Articles