Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill a temp table from stored procedure without knowing it's schema in SQL Server

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.

like image 910
shrekDeep Avatar asked Dec 06 '25 06:12

shrekDeep


1 Answers

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

Insert results of a stored procedure into a temporary table

like image 74
Naveen Kumar Alone Avatar answered Dec 08 '25 20:12

Naveen Kumar Alone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!