0

I want to know if it is possible to insert to a table from a specific column of result from a stored procedure?

Something like:

declare @temp as table(
id int
)

insert @temp
exec getlistofStudents --returns multiple columns

this is an example only, Thanks for the help..

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Unknown
  • 51
  • 3
  • 11
  • possible duplicate of [How to SELECT \* INTO \[temp table\] FROM \[stored procedure\]](http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure) –  Jun 26 '14 at 02:41
  • you can get all columns from stored proc not a single column.. – Azar Jun 26 '14 at 03:12

1 Answers1

1

You can take a 2 step approach. First INSERT INTO a #TempTable, then populate the @TempVariable with another INSERT INTO, selecting the single column.

DECLARE @temp AS TABLE
(
   ID int
);

CREATE TABLE #tempTable1
(
   Column1 int,
   Column2 int   
);

INSERT INTO #tempTable1
Exec getlistofStudents

INSERT INTO @temp
SELECT Column1 FROM #tempTable1
g2server
  • 5,037
  • 3
  • 29
  • 40