Execute TSQL using OpenRowSet

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);Trusted_Connection=yes;',
     'EXEC TestTest.dbo.[getBusinessLineHistory]')

SELECT * FROM #MyTempTable
原文地址:https://www.cnblogs.com/aot/p/2943115.html