1

我有一个大查询,它有多个连接,如下所示。现在我必须调整这个查询。

当前逻辑是:如果 AppealOutcome Code = F/D/P 然后插入 ReAdjustedClaimControlNumber。

我需要将我的逻辑更改为:对于处置 F/D/P,当 MonthlyApepalFile 中的 ReAdjustmentId 为空时,使用 AdjustmentID。如果 AdjustmentId 也为空,则使用 ClaimControlNumber。

任何人都可以抛出任何快捷方式吗?

Insert into rec.RecoveryClaims (ClaimControlKey, ClaimOutcomeCode, ClaimControlNumber )
select 
             A.ClaimControlKey
             ,ClaimOutcomeCode

            ,CASE   WHEN E.AppealOutcomecode = 'F' THEN E.ReadjustedClaimControlNumber
                    WHEN E.AppealOutcomecode = 'D' THEN E.ReadjustedClaimControlNumber
                    WHEN E.AppealOutcomecode = 'P' THEN E.ReadjustedClaimControlNumber
                    ELSE E.AdjustedClaimControlNumber
                    END  
FROM rec.RecoveryClaims A 
INNER JOIN @ExistingRecoveryClaimControlKey b 
    on a.RecoveryClaimControlKey = b.RecoveryClaimControlKey
INNER JOIN occ.Claims C 
    on c.ClaimControlKey = A.ClaimControlKey
INNER JOIN @OutputRecoveryCases D 
    on D.CaseID = C.CaseId  
INNER JOIN @NewClaimControlNumbers E 
    ON C.CaseId = E.CaseID 
    AND A.ClaimControlKey = E.ClaimControlKey 
4

1 回答 1

3

您可以使用以下命令折叠该CASE语句IN

,CASE   WHEN E.AppealOutcomecode IN ('F', 'D', 'P') 
        THEN E.ReadjustedClaimControlNumber
        ELSE E.AdjustedClaimControlNumber
END 

接下来,如果我了解您的要求,下一部分将如下所示:

,CASE   WHEN Disposition IN ('F', 'D', 'P') 
        THEN COALESCE(ReAdjustmentId , AdjustmentID, ClaimControlNumber)
END

编辑:

如果字符串为空而不是NULL,则可以NULLIF与 结合使用COALESCE

,CASE   WHEN Disposition IN ('F', 'D', 'P') 
        THEN COALESCE(
            NULLIF(ReAdjustmentId, '') , 
            NULLIF(AdjustmentID, ''), 
            NULLIF(ClaimControlNumber, '')
        )
END
于 2013-01-30T21:20:09.057 回答