Hey guys,
I have the following query:
Query runs just fine, but I was alarmed to see two records for each SSN. The duplication is occuring because the members are meeting both conditions in my CASE statement.
For example, this person's record in the DSNP.PR01_T_PYMT_CMPNT looks like this:
SSN ANTY_PYMT_DT CMPNT_TYPE_CD
33344555 2010-05-01 20
3334455 2010-05-01 33
Multiple records in the table for the same SSN, and the only difference in the record is the type code. So this person is both YES and NO.
I need to find a way that will return only one record as YES for this person.
I have the following query:
Code:
SELECT DISTINCT A.recip_ssn_nbr, A.PAYEE_NM, B.MBR_ADDR_TX, C.CITY_ID_NM, C.STATE_ID_CD,
C.POST_ZIP_CD, A.RECIP_RETIR_DT, A.RECIP_RETIR_DT2,
D.MBR_BIRTH_DT,
CASE WHEN E.CMPNT_TYPE_CD IN ('33', '34') THEN 'YES' ELSE 'NO' END AS PARTICIPATING
FROM DSNP.PR01_T_RECIP_SYS A,
DSNP.PR01_T_MBR_ADDR B,
DSNP.PR01_T_MBR_CITY C,
DSNP.PR01_T_MBR D,
DSNP.PR01_T_PYMT_CMPNT E
WHERE A.RECIP_SSN_NBR=B.MBR_SSN_NBR
AND A.RECIP_SSN_NBR=C.MBR_SSN_NBR
AND A.RECIP_SSN_NBR=D.MBR_SSN_NBR
AND A.RECIP_SSN_NBR=E.RECIP_SSN_NBR
AND A.BENEF_STAT_CD = ('AC')
AND A.RECIP_TYPE_CD = '10'
AND A.AGTY_SYS_CD = 'ASPRS'
AND E.ANTY_PYMT_DT = '2010-05-01'
Query runs just fine, but I was alarmed to see two records for each SSN. The duplication is occuring because the members are meeting both conditions in my CASE statement.
For example, this person's record in the DSNP.PR01_T_PYMT_CMPNT looks like this:
SSN ANTY_PYMT_DT CMPNT_TYPE_CD
33344555 2010-05-01 20
3334455 2010-05-01 33
Multiple records in the table for the same SSN, and the only difference in the record is the type code. So this person is both YES and NO.
I need to find a way that will return only one record as YES for this person.