I want to Execute one procedure from another procedure and store specific columns from the result of procedure in a temp table without declaring it but Columns are not known and changes depends on the conditions.
I have tried following code but its not working
select * into #Temp1 from Exec(Procedure @parameter)
Is there any way to do this?
Use OPENROWSET
to insert the SP's result into temp
table
Before using OPENROWSET
you have to configure Ad Hoc Distributed Queries
sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO
SELECT * INTO #Temp
FROM OPENROWSET('SQLNCLI', 'Server=yourservername;Trusted_Connection=yes;',
'EXEC Procedure @parameter')
SELECT * FROM #Temp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.