SELECT A.EMPLID , 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 IN ('B','O') AND D.RELATIONSHIP = 'PI' AND D.SEX = 'F' AND B.COUNTRY = 'THA' AND B.NATIONAL_ID_TYPE = 'PID' 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)
|