So i have a temporary table that I need to populate with the records that have to deal with enrollment history
I work with a dataset that looks like this:
sccphidsid enroll_date disenroll_date status
abc123x 2009-01-01 2010-31-12 0
abc123x 2011-01-01 null 0
abc123x 2011-03-01 2012-01-01 0
So I need it to return all records with the same sccphidsid and return them including the null and not null values.
The conditions it has to meet are
- Disenroll dates are not null
- Disenroll dates are null and
- records have multiple disenroll_dates
Current Solution:
select *, count(disenroll_date is null)
from enrollment _test
where Status = 0
group by Sub_Client_Cd, Policy_Holder_ID, Suffix_ID
having count(disenroll_date is null) > 1;
However this is returning too many records, is there a way to isolate this query down, maybe simpler, that can prevent this from returning too many records by constraints or parameters?
Thanks all