3

I have a question here regarding filling temp table from stored procedures in SQL Server. When we already have table schema of a table we can fill it from stored procedure as:

Create #tempTable (Id int, Value varchar(50))

Insert into #tempTable 
exec GetValues

Where GetValues returns the same schema as declared for #tempTable.

Here is another case when we fill a temp table from another table

Select colA,colB into #tempTableA from SomeTable

Here we don't need to know the schema of #tempTableA, it will be same as based on selected columns from table SomeTable.

My question is: how can we fill a #temptable without knowing it's schema, from a stored procedure? As we do when filling a temp table from some other table.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
shrekDeep
  • 2,260
  • 7
  • 27
  • 39

1 Answers1

1
SELECT * INTO #tmpTable FROM OPENQUERY(YOURSERVERNAME, 'EXEC test.dbo.prc_test 1');

Insert results of a stored procedure into a temporary table

Community
  • 1
  • 1
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57