SELECT papf.person_number
,ppnf.full_name
,fdv.file_name
,fdv.dm_document_id
,hdpr.date_from
,hdpr.date_to
FROM per_periods_of_service ppos
,per_all_people_f papf
,per_person_names_f ppnf
,HR_DOCUMENTS_OF_RECORD hdpr
,HR_DOCUMENT_TYPES_TL hdtl
,FND_ATTACHED_DOCUMENTS fda
,fnd_documents_vl fdv
WHERE ppos.date_start = (SELECT MAX(ppos1.date_start)
FROM per_periods_of_service ppos1
WHERE ppos1.person_id = ppos.person_id
AND ppos1.period_type = 'E'
AND ppos1.primary_flag = 'Y'
AND ppos1.date_start <= TRUNC(SYSDATE)
)
AND ppos.period_type = 'E'
AND ppos.primary_flag = 'Y'
AND TRUNC(SYSDATE) BETWEEN ppos.date_start
AND NVL(ppos.actual_termination_date,TRUNC(SYSDATE))
AND papf.person_id = ppos.person_id
AND TRUNC(SYSDATE) BETWEEN papf.effective_start_date
AND papf.effective_end_date
AND ppnf.person_id = ppos.person_id
AND TRUNC(SYSDATE) BETWEEN ppnf.effective_start_date
AND ppnf.effective_end_date
AND ppnf.name_type = 'GLOBAL'
AND hdpr.person_id = papf.person_id
AND TRUNC(SYSDATE) BETWEEN NVL(hdpr.date_from,TRUNC(SYSDATE))
AND NVL(hdpr.date_to,TRUNC(SYSDATE))
AND hdtl.DOCUMENT_TYPE_ID = hdpr.DOCUMENT_TYPE_ID
AND hdtl.document_type = 'Payslip'
AND hdtl.language = 'US'
AND fda.entity_name = 'HR_DOCUMENTS_OF_RECORD'
AND fda.pk1_value = hdpr.DOCUMENTS_OF_RECORD_ID
AND fdv.document_id = fda.document_id
I hope this blog post was helpful for you. If you have any questions or feedback, please leave a comment below.