如何将select语句与存储过程结合使用[复制]

时间:2021-10-04 08:01:47

This question already has an answer here:

这个问题在这里已有答案:

How can I achieve something like this :

我怎样才能实现这样的目标:

SELECT * DISTINCT FROM 
(execute dbo.MyStoredProcedure(@ID1,@ID2))

suppose that's inside another stored procedure.

假设它在另一个存储过程中。

How can I call a stored procedure from another stored procedure and get the result as a table (my select is intended for that)

如何从另一个存储过程调用存储过程并将结果作为表格获取(我的选择用于此目的)

2 个解决方案

#1


2  

Try

DECLARE @TableTemp TABLE (--declare parameters, ouput from SP)

INSERT INTO @TableTemp
EXEC dbo.MyStoredProcedure @ID1,@ID2

SELECT * FROM @TableTemp 

#2


1  

You can do something like this.

你可以做这样的事情。

INSERT INTO #temp 
EXEC MyStoredProcedure(@ID1,@ID2)

SELECT * FROM #temp

#1


2  

Try

DECLARE @TableTemp TABLE (--declare parameters, ouput from SP)

INSERT INTO @TableTemp
EXEC dbo.MyStoredProcedure @ID1,@ID2

SELECT * FROM @TableTemp 

#2


1  

You can do something like this.

你可以做这样的事情。

INSERT INTO #temp 
EXEC MyStoredProcedure(@ID1,@ID2)

SELECT * FROM #temp