SELECT EMPLID , NAME , RELATIONSHIP , NATIONAL_ID , NAME_PREFIX , FIRST_NAME , LAST_NAME FROM ( SELECT A.EMPLID , ROW_NUMBER () OVER (PARTITION BY A.EMPLID ORDER BY A.DEPENDENT_BENEF ASC ) SEQ , C.NAME , D.RELATIONSHIP , B.NATIONAL_ID , C.NAME_PREFIX , C.FIRST_NAME , C.LAST_NAME FROM PS_DEP_BEN A , PS_DEP_BENEF_NID B , PS_DEP_BEN_NAME C , PS_DEP_BEN_EFF D WHERE D.DEP_BENEF_TYPE ='B' AND D.RELATIONSHIP = 'C' AND B.COUNTRY = 'THA' AND B.NATIONAL_ID_TYPE = 'PID' AND D.STUDENT='Y' AND A.EMPLID = B.EMPLID AND A.DEPENDENT_BENEF = B.DEPENDENT_BENEF AND A.EMPLID = C.EMPLID AND A.DEPENDENT_BENEF = C.DEPENDENT_BENEF AND A.EMPLID =D.EMPLID AND A.DEPENDENT_BENEF = D.DEPENDENT_BENEF AND D.EMPLID = C.EMPLID AND D.DEPENDENT_BENEF = C.DEPENDENT_BENEF AND C.EFFDT = ( SELECT MAX(C_ED.EFFDT) FROM PS_DEP_BEN_NAME C_ED WHERE C.EMPLID = C_ED.EMPLID AND C.DEPENDENT_BENEF = C_ED.DEPENDENT_BENEF AND C_ED.EFFDT <= %CurrentDateIn ) AND D.EFFDT = ( SELECT MAX(D1.EFFDT) FROM PS_DEP_BEN_EFF D1 WHERE D1.EMPLID = D.EMPLID AND D1.DEPENDENT_BENEF = D.DEPENDENT_BENEF AND D1.EFFDT <= %CurrentDateIn ) ORDER BY A.DEPENDENT_BENEF ASC ) WHERE SEQ=3
|