从另一个存储过程执行存储过程

时间:2021-07-07 20:10:59

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?

有没有办法做到这一点?

1 个解决方案

#1


1  

Use OPENROWSET to insert the SP's result into temp table

使用OPENROWSET将SP的结果插入临时表

Before using OPENROWSET you have to configure Ad Hoc Distributed Queries

在使用OPENROWSET之前,您必须配置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

#1


1  

Use OPENROWSET to insert the SP's result into temp table

使用OPENROWSET将SP的结果插入临时表

Before using OPENROWSET you have to configure Ad Hoc Distributed Queries

在使用OPENROWSET之前,您必须配置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