SELECT a.emplid , b.name FROM PS_EX_TAUTH_HDR a , ps_personal_data b WHERE (a.travel_auth_status IN ('PND','DEN','DNA','DNU') OR (A.TRAVEL_AUTH_STATUS = 'CLS' AND A.USER_CANCEL_PB IN ('U','I'))) AND b.emplid = a.emplid AND (NOT EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.TRAVEL_AUTH_ID = A.TRAVEL_AUTH_ID) OR (EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.TRAVEL_AUTH_ID = A.TRAVEL_AUTH_ID) AND NOT EXISTS ( SELECT 'X' FROM PS_EX_APRVL_HIST H WHERE H.EX_DOC_ID = A.TRAVEL_AUTH_ID AND H.EX_DOC_TYPE = 'T' AND ACTION_NAME = 'SUB')) OR (EXISTS ( SELECT 'X' FROM PS_KK_SOURCE_HDR D WHERE D.TRAVEL_AUTH_ID = A.TRAVEL_AUTH_ID) AND EXISTS ( SELECT 'X' FROM PS_EX_APRVL_HIST H WHERE H.EX_DOC_ID = A.TRAVEL_AUTH_ID AND H.EX_DOC_TYPE = 'T' AND ACTION_NAME IN ('SBR', 'WRD') 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))))
|