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.

4

1 回答 1

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

将存储过程的结果插入临时表

于 2013-06-28T08:45:30.530 回答