2017-08-11 6 views
0

評価する値のリストがあります。例では、私は、ストアドプロシージャの出力が1列と4列エイリアス左外側から返され得る参加を有する列と手順の値を比較します

'16-%', '45-%','A1%','125%' 

の下方に設けられ

例:

Max(db_util.Efn_name_wid(tdl_tran.reason_code_id, 
       remit_rmc.remit_code_id, remit_rmc.remit_code_name, 'Reason') 
) AS DEN_REASON 

, Max(RMC_1.remit_code_name) 
     AS REMIT_CD1 

,Max(RMC_2.remit_code_name) 
     AS REMIT_CD2 

,Max(RMC_3.remit_code_name) 
     AS REMIT_CD3 

,Max(RMC_4.remit_code_name) 
     AS REMIT_CD4 

ロジックIビルドしようとしています:

IF DEN_REASONのような(リストの任意の値)

次に、同じリストに対してremit_cd1の列を評価します(リスト内の値と一致する場合)。次に、remit_cd2、remit_cd3、remit_cd4に進み、リスト内の値と一致しない最初の送金コードを見つけます。

最終的に1つの値を返そうとしています。私はこのCASE文は何が必要かもしれないと思う

答えて

0

:あなたは、サブクエリであなたのLIKE試用版をやった場合

SELECT CASE 
    WHEN DEN_REASON LIKE (/* your set of values */) 
     AND REMIT_CD1 LIKE (/* your set of values */) 
     AND REMIT_CD2 LIKE (/* your set of values */) 
     AND REMIT_CD3 LIKE (/* your set of values */) 
     AND REMIT_CD4 NOT LIKE (/* your set of values */) 
     THEN REMIT_CD4 
    WHEN DEN_REASON LIKE (/* your set of values */) 
     AND REMIT_CD1 LIKE (/* your set of values */) 
     AND REMIT_CD2 LIKE (/* your set of values */) 
     AND REMIT_CD3 NOT LIKE (/* your set of values */) 
     THEN REMIT_CD3 
    WHEN DEN_REASON LIKE (/* your set of values */) 
     AND REMIT_CD1 LIKE (/* your set of values */) 
     AND REMIT_CD2 NOT LIKE (/* your set of values */) 
     THEN REMIT_CD2 
    WHEN DEN_REASON LIKE (/* your set of values */) 
     AND REMIT_CD1 NOT LIKE (/* your set of values */) 
     THEN REMIT_CD1 
    WHEN DEN_REASON NOT LIKE (/* your set of values */) 
     THEN DEN_REASON 
    END AS YourSingleResult 

FROM --your query 
( SELECT 
    Max(db_util.Efn_name_wid(tdl_tran.reason_code_id, 
     remit_rmc.remit_code_id, remit_rmc.remit_code_name, 'Reason') 
     ) AS DEN_REASON 
    ,Max(RMC_1.remit_code_name) AS REMIT_CD1 
    ,Max(RMC_2.remit_code_name) AS REMIT_CD2 
    ,Max(RMC_3.remit_code_name) AS REMIT_CD3 
    ,Max(RMC_4.remit_code_name) AS REMIT_CD4 
    -- and the rest of your query, that you omitted from your example above 
) 

はその後、再び、それは短いかもしれません。このように:

SELECT CASE 
    WHEN MatchesDenReason = 1 
     AND MatchesCD1 = 1 
     AND MatchesCD2 = 1 
     AND MatchesCD3 = 1 
     AND MatchesCD4 = 0 
     THEN REMIT_CD4 
    WHEN MatchesDenReason = 1 
     AND MatchesCD1 = 1 
     AND MatchesCD2 = 1 
     AND MatchesCD3 = 0 
     THEN REMIT_CD3 
    WHEN MatchesDenReason = 1 
     AND MatchesCD1 = 1 
     AND MatchesCD2 = 0 
     THEN REMIT_CD2 
    WHEN MatchesDenReason = 1 
     AND MatchesCD1 = 0 
     THEN REMIT_CD1 
    WHEN MatchesDenReason = 0 
     THEN DEN_REASON 
    END AS YourSingleResult 

FROM --your query 
( SELECT 
    Max(db_util.Efn_name_wid(tdl_tran.reason_code_id, 
     remit_rmc.remit_code_id, remit_rmc.remit_code_name, 'Reason') 
     ) AS DEN_REASON 
    ,CASE WHEN Max(db_util.Efn_name_wid(tdl_tran.reason_code_id, 
     remit_rmc.remit_code_id, remit_rmc.remit_code_name, 'Reason') 
     ) LIKE (/* your list */) 
      THEN 1 ELSE 0 END AS MatchesDenReason 
    ,Max(RMC_1.remit_code_name) AS REMIT_CD1 
    ,CASE WHEN Max(RMC_1.remit_code_name) LIKE (/* your list */) 
      THEN 1 ELSE 0 END AS MatchesCD1 
    ,Max(RMC_2.remit_code_name) AS REMIT_CD2 
    ,CASE WHEN Max(RMC_2.remit_code_name) LIKE (/* your list */) 
      THEN 1 ELSE 0 END AS MatchesCD2 
    ,Max(RMC_3.remit_code_name) AS REMIT_CD3 
    ,CASE WHEN Max(RMC_3.remit_code_name) LIKE (/* your list */) 
      THEN 1 ELSE 0 END AS MatchesCD3 
    ,Max(RMC_4.remit_code_name) AS REMIT_CD4 
    ,CASE WHEN Max(RMC_4.remit_code_name) LIKE (/* your list */) 
      THEN 1 ELSE 0 END AS MatchesCD4 
    -- and the rest of your query, that you omitted from your example above 
) 
関連する問題