Bank details of employees with bank name and account.
SELECT DISTINCT a.employee_number,
a.full_name employee_name,
TRIM (d.segment1) bank_name,
TRIM (d.segment2) bank_name_arabic,
TRIM (d.segment6) IBAN
FROM per_all_people_f a,
per_all_assignments_f b,
pay_personal_payment_methods_f c,
PAY_EXTERNAL_ACCOUNTS d
WHERE a.person_id = b.person_id
AND b.assignment_id = c.assignment_id
AND c.external_account_id = d.external_account_id
AND a.employee_number NOT IN
(SELECT papf.employee_number
FROM apps.per_all_people_f papf,
apps.per_periods_of_service ppos
WHERE 1 = 1 AND papf.person_id = ppos.person_id
AND ppos.period_of_service_id =
(SELECT MAX (period_of_service_id)
FROM per_periods_of_service
WHERE person_id = papf.person_id)
AND ppos.actual_termination_date < TRUNC (SYSDATE))