SELECT A.EMPLID , A.DEPENDENT_BENEF , CASE WHEN A.BIRTHDATE IS NULL THEN ' ' ELSE %Substring(%Cast(A.BIRTHDATE, Date, Character),1,4) %Concat %Substring(%Cast(A.BIRTHDATE, Date, Character),6,2) %Concat %Substring(%Cast(A.BIRTHDATE, Date, Character),9,2) END , CASE WHEN B.NATIONAL_ID IS NULL THEN ' ' ELSE B.NATIONAL_ID END , A.NAME_DISPLAY , CASE WHEN A.RELATIONSHIP = 'SP' THEN '03' WHEN A.RELATIONSHIP = 'C' THEN '04' WHEN A.RELATIONSHIP = 'RC' THEN '04' WHEN A.RELATIONSHIP = 'FC' THEN '06' WHEN A.RELATIONSHIP = 'OC' THEN '06' WHEN A.RELATIONSHIP = 'SC' THEN '06' WHEN A.RELATIONSHIP = 'P' THEN '08' WHEN A.RELATIONSHIP = 'SA' THEN '08' ELSE '10' END FROM PS_DEPENDENT_BENEF A LEFT OUTER JOIN PS_DEP_BENEF_NID B ON B.EMPLID = A.EMPLID AND B.DEPENDENT_BENEF = A.DEPENDENT_BENEF AND B.COUNTRY = 'BRA' AND B.NATIONAL_ID_TYPE = 'CPF'
|