Recently started working with this query that I picked up from a co-worker, and it is extremely slow.
I have added what I would consider at min the proper indexes used within the where clause, but it is still taking way too long.
Any thoughts or tips for re-writting this for max eff would be appreciated.
SELECT DISTINCT CaseT.CaseNum CaseNum
FROM CaseTable CaseT
LEFT JOIN CaseLocationtable CLT ON CaseT.CaseNum = CLT.CaseNum
INNER JOIN CodeTable CodeT ON CaseT.Status = CodeT.Code,
baseclaimrates bcr
left join CaseLocationTable A on bcr.planoption = A.hmoplan and
bcr.healthplan = 'HMO' and A.hmoplan is not null
left join CaseLocationTable B on bcr.planoption = B.posplan AND
bcr.healthplan = 'POS' and B.posplan is not null
left join CaseLocationTable C on bcr.planoption = C.posplusplan AND
bcr.healthplan = 'POS+'
and C.posplusplan is not null
WHERE 1=1
AND ((CaseT.CaseNum = A.CaseNum)
OR(CaseT.CaseNum = B.CaseNum)
OR(CaseT.CaseNum = C.CaseNum))
AND (CaseT.GroupType = bcr.GroupType)
AND ((CaseT.ReceivedDate >= bcr.EffDate)
AND (CaseT.ReceivedDate <= bcr.EndDate))
AND bcr.plan_key = '122'
I have added what I would consider at min the proper indexes used within the where clause, but it is still taking way too long.
Any thoughts or tips for re-writting this for max eff would be appreciated.
SELECT DISTINCT CaseT.CaseNum CaseNum
FROM CaseTable CaseT
LEFT JOIN CaseLocationtable CLT ON CaseT.CaseNum = CLT.CaseNum
INNER JOIN CodeTable CodeT ON CaseT.Status = CodeT.Code,
baseclaimrates bcr
left join CaseLocationTable A on bcr.planoption = A.hmoplan and
bcr.healthplan = 'HMO' and A.hmoplan is not null
left join CaseLocationTable B on bcr.planoption = B.posplan AND
bcr.healthplan = 'POS' and B.posplan is not null
left join CaseLocationTable C on bcr.planoption = C.posplusplan AND
bcr.healthplan = 'POS+'
and C.posplusplan is not null
WHERE 1=1
AND ((CaseT.CaseNum = A.CaseNum)
OR(CaseT.CaseNum = B.CaseNum)
OR(CaseT.CaseNum = C.CaseNum))
AND (CaseT.GroupType = bcr.GroupType)
AND ((CaseT.ReceivedDate >= bcr.EffDate)
AND (CaseT.ReceivedDate <= bcr.EndDate))
AND bcr.plan_key = '122'