开发者

Using Stored Procedure into Select (T-SQL)

开发者 https://www.devze.com 2022-12-24 07:25 出处:网络
I need to access the result of a stored procedure within a开发者_JAVA技巧 select statement, i.e.:

I need to access the result of a stored procedure within a开发者_JAVA技巧 select statement, i.e.:

SELECT * FROM [dbo].[sp_sample]

in SQL_Server 2005.


This isn't possible. You would have to create a temporary table to store the results.

Create Table #tmp
(
...
)
Insert into #tmp
Exec dbo.StoredProcedure

The table structure must match the output of the Stored Procedure.


@Barry is right you need to create a temp table and insert into it first, then join that table in your select.

However, there are numerous ways for sharing data between stored procedures, see this excellent article: How to Share Data Between Stored Procedures by Erland Sommarskog

One method that may work for you is to "share" a temp table. The #temp table is created in the Parent procedure and can be used by the Child: http://www.sommarskog.se/share_data.html#temptables

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号