Insert Output of a stored procedure to a temp table

t-sql

Solution

To use temp table this way in `INSERT INTO` you should define this table first.

CREATE TABLE #tblTemp(
ID int,
....
)

In T-SQL a temp table can be created automatically using following command:

select * into #tblTemp
from table

You can use this syntax in your case with stored procedure results using `OPENROWSET`.

Here is the answer on SO which can help

Problem

when trying to write the output of a stored procedure into a temp table, I get the error message Msg 208, Level 16, State 0, Line 4 Invalid object name '#tblTemp '. My query is this: ``` DECLARE @group_name varchar(250) SET @group_name = 'somevalue' INSERT INTO #tblTemp EXEC mySchema.sp_MyStoredProc @group_name OUTPUT SELECT * FROM #tblTemp DROP TABLE #tblTemp ``` What is wrong here? Thanks for your help!

Original source

Related problems