SQL Server How to create a table from the results of a Stored Procedure execution

4szc88ey  于 2023-06-28  发布在  其他
关注(0)|答案(1)|浏览(130)

The execution of the Stored Procedure below results in the following output

The above output isn't create in a view or a table that can be queried later.

Can someone show me how to modify the procedure such that the output results in the creation of table called, say dbo.mytesttable

The Stored Procedure is as follows:

CREATE PROC outbound.usp_Terminals(@AsOfDate date)

AS

SELECT  
    airport_code,
    airport_name,
    airport_city,
    airport_state
FROM 
    dbo.fnGetAirports(@AsOfDate)

GO

A friend suggested the following code, but it didn't work:

DECLARE @date date
SET @date = ...

INSERT INTO #prebuilt_table
EXEC dbo.outbound.usp_Terminals @date
kqlmhetl

kqlmhetl1#

There are a number of solutions, the simplest of the solutions is as follows:

select 
    airport_code,
    airport_name,
    airport_city,
    airport_state
into MyTableName
from dbo.fnGetAirports(@AsOfDate)

相关问题