I have a big query that has multiple Joins as below.
Now I have to tune this query.
Current Logic is: If AppealOutcome Code = F/D/P then Insert ReAdjustedClaimControlNumber.
I need to change my Logic as: For Disposition F/D/P, When ReAdjustmentId is empty from MonthlyApepalFile, Use AdjustmentID. If AdjustmentId is also Empty, Use ClaimControlNumber.
Can anyone please throw any shortcuts?
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
You can collapse that
CASEstatement by usingIN:Next, if I understand your requirements, the next portion would look like:
EDIT:
If the strings are empty instead of
NULL, you can useNULLIFin conjunction withCOALESCE: