Insert results of a stored procedure into a temporary table

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Insert results of a stored procedure into a temporary table

Message par ForumBot »

Insert results of a stored procedure into a temporary table
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Insert results of a stored procedure into a temporary table

Message par ForumBot »

You can use [OPENROWSET](http://msdn.microsoft.com/en-us/library/ms190312%28v=sql.100%29.aspx) for this. Have a look. I've also included the sp_configure code to enable Ad Hoc Distributed Queries, in case it isn't already enabled.

```
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

```
Répondre

Revenir à « SQL Server »