0

我想将两个表的结果组合在一起,因为当我分开做时,我得到 NULLS

这是我的代码

DECLARE @origSiteID int = 836,
    @NewSiteID int = 838


SELECT tblControls_Rooms.ID, @origSiteID
FROM tblControls_Rooms
WHERE SiteID = @OrigSiteID

SELECT tblControls_Rooms.ID, @NewSiteID
FROM tblControls_Rooms
WHERE SiteID = @newSiteID

当我运行它时:

ID  (No column name)
1942    836
1943    836
1944    836
1945    836
1946    836

ID  (No column name)
2025    838
2026    838
2027    838
2028    838

我希望结果是:

ID  (No column name)
1942    836
1943    836
1944    836
1945    836
1946    836
2025    838
2026    838
2027    838
2028    838
4

2 回答 2

2

联盟会工作,你也可以使用......

SELECT ID, SiteID
FROM tblControls_Rooms
WHERE SiteID IN (@OrigSiteID, @NewSiteID)
于 2013-07-30T21:52:34.090 回答
0

我认为这对你有用:

SELECT DISTINCT(tblControls_Rooms.ID), tblControls_Rooms.SiteID
FROM tblControls_Rooms
WHERE SiteID = @OrigSiteID
OR SiteID = @newSiteID

您可能不需要 DISTINCT

于 2013-07-30T21:53:04.507 回答