在 Select 中使用存储过程 (T-SQL) [英] Using Stored Procedure into Select (T-SQL)

查看:49
本文介绍了在 Select 中使用存储过程 (T-SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 select 语句中访问存储过程的结果,即:

I need to access the result of a stored procedure within a select statement, i.e.:

SELECT * FROM [dbo].[sp_sample]

在 SQL_Server 2005 中.

in SQL_Server 2005.

推荐答案

@Barry 是对的您需要先创建一个临时表并插入其中,然后在您的选择中加入该表.

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

但是,存储过程之间共享数据的方法有很多种,请参阅这篇优秀文章:How to ShareErland Sommarskog 的存储过程之间的数据

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

一种可能对您有用的方法是共享"临时表.#temp 表是在 Parent 过程中创建的,可供 Child 使用:http://www.sommarskog.se/share_data.html#temptables

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

这篇关于在 Select 中使用存储过程 (T-SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆