如何在我的存储过程中组合选择语句导致单个结果集 [英] How Do I Combine Select Statements In My Stored Procedure Resulting In Single Result Set

查看:81
本文介绍了如何在我的存储过程中组合选择语句导致单个结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter PROCEDURE spInterventionValues
(
    @TableVar ILVariable1 READONLY,
    @NetworkName nvarchar(100)
)
AS
BEGIN
    SET NOCOUNT ON;
   
       
      select obj2.RoadID from tblNetwork obj1  join
       tblRoad obj2 on obj1.NetworkID=obj2.NetworkID 
  where obj1.Name=@NetworkName and obj2.SectionReference IN(SELECT SectionReference From @TableVar)
     
      select XSPID from tblXSP where Name IN(SELECT Name From @TableVar)
	  
      select Distance,Value from @TableVar 
      
    
 
    --WHERE ID IN (SELECT ID FROM @TableVar)
        
END
GO





这是我的存储过程......

我需要将select语句组合成单个结果集或单个select语句



This is my stored procedure...
I need to combine select statement into a single result set or single select statement

推荐答案

如果你想要根据3个表获得结果,然后使用加入 [ ^ ]



如果要将3个select语句结果合并为单个,然后你必须记住一个字段应该相等的东西,如果你想了解更多关于这个参考下面的链接 Union [ ^ ]
If you want to get result based on 3 tables then use Joins[^]

If you want to combine the 3 select statement result into single, then you must remember one thing fields should be equal, if you want to know more about this refer below link Union[^]


我想你是什么需要是 UNION(Transact-SQL ) [ ^ ]声明。



但是:您的所有查询都必须选择相同数量的列;我可以看到你的第三个SELECT查询是获取两列,而前两个只获取一列。



希望这会有所帮助。
I think what you need is UNION (Transact-SQL)[^] statement.

BUT: all your queries must select the same number of columns ; I can see that your third SELECT query is fetching two columns, whereas both first ones only fetch one.

Hope this helps.


这篇关于如何在我的存储过程中组合选择语句导致单个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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