Query to fetch Legal Employer of Employee

 Query to fetch Legal Employer of Employee


select papf.person_number,
       papf.person_id,
       papf.start_date,
       ppnf.full_name employee_full_name,
       paam.assignment_number,
       ple.name       legal_employer_name
from   per_all_people_f papf,
       per_all_assignments_m paam,
       per_person_names_f ppnf,
       per_legal_employers ple
where  1 = 1
       and trunc(sysdate) between papf.effective_start_date and
                                  papf.effective_end_date
       and papf.person_id = ppnf.person_id
       and trunc(sysdate) between ppnf.effective_start_date and
                                  ppnf.effective_end_date
       and ppnf.name_type = 'GLOBAL'
       and papf.person_id = paam.person_id
       and trunc(sysdate) between paam.effective_start_date and
                                  paam.effective_end_date
       and paam.assignment_status_type in ( 'ACTIVE' ) -- Active Assignment
       and paam.assignment_type in ( 'E' ) -- Type Employee
       and paam.primary_flag = 'Y' -- primary assignment
       and paam.legal_entity_id = ple.organization_id(+)
       and trunc(sysdate) between ple.effective_start_date and
                                  ple.effective_end_date
       and ple.status = 'A'
--and papf.person_number = :p_person_number -- parameter

No comments:

Post a Comment