0

I have a scenario where I need to execute stored procedure in inline query and store their output into Temp(Temporary) table and then further filters onto that Temp table , depending upon the requirements.

The examples I have seen are like, creating a #Temp table with all columns definitions, but I don't want to define each and every column for the temporary table, rather dynamically creation as per SP output.

Can anybody guide me how to do that?

Bridge
  • 29,818
  • 9
  • 60
  • 82
DareDevil
  • 5,249
  • 6
  • 50
  • 88
  • possible duplicate of [Insert results of a Stored Procedure into a Temporary Table](http://stackoverflow.com/questions/653714/insert-results-of-a-stored-procedure-into-a-temporary-table) – Bridge Jan 30 '15 at 13:10

1 Answers1

1

You could do that using OPENQUERY, but from my own experience i had lots of difficulties with it (permissions, quite a lot of restrictions and etc.)

SELECT *
INTO #TempTable
FROM OPENQUERY(linkedserver, 'EXEC dbo.Sproc');
Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107