SELECT DISTINCT B.SOCS_AUTH_KEY_ESP , C.GPES_YEAR , C.GPES_MONTH , B.COMPANY , A.DESCR FROM PS_SOCS_SETHD_ESP B , PS_GPES_CRT_CMP_VW C , PS_GPES_SYS_CALEND D , PS_COMPANY_TBL A WHERE B.COMPANY = C.COMPANY AND C.GPES_YEAR = D.CALYEAR AND C.GPES_MONTH = D.GPES_MONTH AND B.EFFDT = ( SELECT MAX(ED.EFFDT) FROM PS_SOCS_SETHD_ESP ED WHERE ED.COMPANY = B.COMPANY AND ED.EFFDT <= D.GPES_MONTH_BGN_DT) AND B.COMPANY = A.COMPANY AND A.EFFDT = ( SELECT MAX(ED1.EFFDT) FROM PS_COMPANY_TBL ED1 WHERE ED1.COMPANY = A.COMPANY AND ED1.EFFDT <= D.GPES_MONTH_BGN_DT)
|