0

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

2
  • The conditions "Disenroll dates are not null" and "Disenroll dates are null" do not seem to be valid.. Commented Mar 9, 2012 at 20:32
  • I was referring to disenroll date is null and a case where the disenroll_date is not null with a valid date...not "not null". Commented Mar 14, 2012 at 19:31

2 Answers 2

1
SELECT Sub_Client_Cd, Policy_Holder_ID, Suffix_ID,
       SUM(CASE WHEN disenroll_date IS NULL THEN 1 ELSE 0 END) AS NullDateCount,
       SUM(CASE WHEN disenroll_date IS NOT NULL THEN 1 ELSE 0 END) AS NotNullDateCount
    FROM enrollment_test
    WHERE Status = 0
    GROUP BY Sub_Client_Cd, Policy_Holder_ID, Suffix_ID
    HAVING COUNT(*) > 1;
Sign up to request clarification or add additional context in comments.

Comments

1

Actually this took care of it... Thanks anyways.

 select *, count(disenroll_date is null) from enrollment_test 
 where  Status = 0 
 and disenroll_date is null 
 group by Sub_Client_Cd, Policy_Holder_ID, Suffix_ID              
 having count(disenroll_date is null) > 1; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.