我有一个大查询,它有多个连接,如下所示。现在我必须调整这个查询。
当前逻辑是:如果 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