Home >Database >Mysql Tutorial >How to Insert Stored Procedure Results into a Temporary Table Using OPENROWSET?

How to Insert Stored Procedure Results into a Temporary Table Using OPENROWSET?

DDD
DDDOriginal
2025-01-25 02:46:09216browse

How to Insert Stored Procedure Results into a Temporary Table Using OPENROWSET?

Using OpenRowSet to insert the storage process into the temporary table

The use of to insert the storage procedure into the temporary table may fail due to grammatical errors. The solution is to use the method.

First of all, you need SELECT * INTO OPENROWSET After enabling, you can use the following code to insert the results of the storage procedure into the temporary table. No need to define the table structure in advance:

In this example, the storage procedure
<code class="language-sql">sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO</code>
return the data of the

table. By , the results of the storage procedure can be effectively inserted into the temporary table

.
<code class="language-sql">CREATE PROC getBusinessLineHistory
AS
BEGIN
    SELECT * FROM sys.databases
END
GO

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

SELECT * FROM #MyTempTable</code>

The above is the detailed content of How to Insert Stored Procedure Results into a Temporary Table Using OPENROWSET?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn