Sometimes we forget about result set of created Stored Procedure and we have need to create a temporary table based on that stored procedure then try the following SQL statement to create a temp table base in the stores procedure by using the following SQL statement-
Syntax-
SELECT * INTO TempTableName FROM OPENROWSET(‘SQLNCLI’, ‘SERVER=Localhost; Trusted_connection= yes;’, ‘EXEC ProcedureName’);
Then
SELECT * from TempTable;
Ex-
First I have create a Stored procedure
CREATE PROCEDURE usp_DemoProcedure
AS
BEGIN
SELECT * FROM Employees
END
Here the following SQL statement is used to create a temp table to store the result set of the stored procedure,
SELECT * INTO #tblTempTable FROM
OPENROWSET('SQLNCLI', 'Server= localhost; Trusted_Connection=yes;', 'EXEC usp_DempProcedure');
Execute the temp table
SELECT * FROM #tblTempTable;
If you are getting error to perform the above SQL statement then you need to enable the ad hoc distributed queries by using the following queries,
sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries'
GO
RECONFIGURE
GO
If you want to show all advance system setting then use the following SQL statement,
sp_configure
To set the default system setting use the following statement,
sp_configure 'Show Advanced Options', 0
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL Create Temp table for stored Procedure:
Sometimes we forget about result set of created Stored Procedure and we have need to create a temporary table based on that stored procedure then try the following SQL statement to create a temp table base in the stores procedure by using the following SQL statement-
Syntax-
Then
Ex-
First I have create a Stored procedure
Here the following SQL statement is used to create a temp table to store the result set of the stored procedure,
Execute the temp table
If you are getting error to perform the above SQL statement then you need to enable the ad hoc distributed queries by using the following queries,
If you want to show all advance system setting then use the following SQL statement,
To set the default system setting use the following statement,