Trying to insert a stored procedure into a temporary table, getting 'an object or column name is missing or empty'

sql-server, t-sql

Solution

Try creating the temp table first:

CREATE TABLE #temp1
(
   COL1 INT,
   COL2 VARCHAR(MAX)   
)

INSERT INTO #temp1 
exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp'

In your case of an extremely wide result set, you may want to use `OPENROWSET`

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

Problem

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 am trying to insert the records into a temporary table. (Stack Overflow posts and other posts say that is how to do it.) But when I try, I get the error: object or column name is missing or empty' When I just run the stored procedure, I get a table that has 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?

Original source

Related problems