gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:14:03 26 4
gpt4 key购买 nike

如何执行SELECT * INTO [临时表] FROM [存储过程]?不是 FROM [Table] 并且没有定义 [temp table]

选择BusinessLinetmpBusLine的所有数据工作正常。

select *
into tmpBusLine
from BusinessLine

我正在尝试相同的操作,但是使用返回数据的存储过程并不完全相同。

select *
into tmpBusLine
from
exec getBusinessLineHistory '16 Mar 2009'

输出消息:

Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'exec'.

我已经阅读了几个创建与输出存储过程具有相同结构的临时表的示例,该表工作正常,但最好不提供任何列。

最佳答案

您可以使用OPENROWSET为了这。看一看。我还添加了 sp_configure 代码来启用临时分布式查询(如果尚未启用)。

CREATE PROC getBusinessLineHistory
AS
BEGIN
SELECT * FROM sys.databases
END
GO

sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO

SELECT * INTO #MyTempTable FROM OPENROWSET('SQLNCLI', 'Server=(local)\SQL2008;Trusted_Connection=yes;',
'EXEC getBusinessLineHistory')

SELECT * FROM #MyTempTable

关于sql - 将存储过程的结果插入临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/653714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com