SELECT a.emplid , b.name FROM PS_EX_SHEET_HDR a , ps_personal_data b WHERE a.sheet_status IN ('PND','DEN','DNA','DNU') AND b.emplid = a.emplid AND (NOT EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.SHEET_ID = A.SHEET_ID) OR (EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.SHEET_ID = A.SHEET_ID) AND NOT EXISTS ( SELECT 'X' FROM PS_EX_APRVL_HIST H WHERE H.EX_DOC_ID = A.SHEET_ID AND H.EX_DOC_TYPE = 'S' AND ACTION_NAME = 'SUB')) OR (EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.SHEET_ID = A.SHEET_ID) AND EXISTS ( SELECT 'X' FROM PS_EX_APRVL_HIST H WHERE H.EX_DOC_ID = A.SHEET_ID AND H.EX_DOC_TYPE = 'S' AND ACTION_NAME IN ('SBR', 'WDR') AND H.SEQ_NUM = ( SELECT MAX(H2.SEQ_NUM) FROM PS_EX_APRVL_HIST H2 WHERE H.EX_DOC_ID = H2.EX_DOC_ID AND H.EX_DOC_TYPE = H2.EX_DOC_TYPE AND H.VERSION_NUM = H2.VERSION_NUM))))
|