0

これらすべてに加えて、IsActive=1のレコードのみを選択できるようにする必要があります。

SELECT DISTINCT 0 as CommunityID,  

                    CASE Libname
                        WHEN 'RKHL' THEN 'ROCK HILL'
                        WHEN 'FTML' THEN 'FORT MILL'
                        WHEN 'LANC' THEN 'LANCASTER'
                        WHEN 'BREV' THEN 'BREVARD'
                        WHEN 'PBTC' THEN 'MIDLANDS-CLEC'
                        WHEN 'PBTI' THEN 'MIDLANDS-ILEC'

                    END AS CommunityDesc,

                    LibName,
                    LibName + '|' AS FilterByID,
                    IsActive 
                    FROM Reference.dbo.Community
                    WHERE LibName <> 'CAROTEL' 
                    UNION
                    SELECT CommunityID, RTRIM(COMMNAME) AS CommunityDesc, LibName, LibName + '|' + RTRIM(COMMNAME) AS FilterByID, IsActive
                    FROM Reference.dbo.Community 

                    WHERE LibName <> 'CAROTEL'
                    ORDER BY 1,3;
4

2 に答える 2

1

IsActive=1ユニオンの両側のWHERE句に追加します。

于 2012-06-04T19:35:43.167 に答える
1

次の方法で結果セットをフィルタリングできます。

 SELECT * 
    FROM (
    SELECT DISTINCT 0 as CommunityID,  

                    CASE Libname
                        WHEN 'RKHL' THEN 'ROCK HILL'
                        WHEN 'FTML' THEN 'FORT MILL'
                        WHEN 'LANC' THEN 'LANCASTER'
                        WHEN 'BREV' THEN 'BREVARD'
                        WHEN 'PBTC' THEN 'MIDLANDS-CLEC'
                        WHEN 'PBTI' THEN 'MIDLANDS-ILEC'

                    END AS CommunityDesc,

                    LibName,
                    LibName + '|' AS FilterByID,
                    IsActive 
                    FROM Reference.dbo.Community
                    WHERE LibName <> 'CAROTEL' 
                    UNION
                    SELECT CommunityID, RTRIM(COMMNAME) AS CommunityDesc, LibName, LibName + '|' + RTRIM(COMMNAME) AS FilterByID, IsActive
                    FROM Reference.dbo.Community 

                    WHERE LibName <> 'CAROTEL'
) i
WHERE IsActive = 1
ORDER BY 1,3;
于 2012-06-04T19:37:24.587 に答える