Friday, July 8, 2016

Query to lists the Grades, their present and next Grade Step, and their corresponding values.

SELECT   DISTINCT
         papf.employee_number    staffno,
         pgrf.value              basic,
         pgrf1.value             basic1,
         pg.name                 grade,
         psp.spinal_point        grade_step,
         psp1.spinal_point       grade_step1
FROM  
per_all_people_f                papf,
per_all_assignments_f paaf,
         per_grades                      pg,
         per_spinal_point_placements_f   psppf,
         per_spinal_point_steps_f        pspsf,
         per_spinal_point_steps_f        pspsf1,
         per_spinal_points               psp,
         per_spinal_points               psp1,
         per_grade_spines_f              pgsf,
         pay_grade_rules_f               pgrf,
         pay_grade_rules_f               pgrf1
WHERE
papf.business_group_id =  P_BUSINESS_GROUP_ID
AND papf.current_employee_flag = 'Y'
         AND TRUNC(SYSDATE)  BETWEEN papf.effective_start_date AND papf.effective_end_date
         AND papf.person_id = paaf.person_id
         AND TRUNC(SYSDATE)  BETWEEN paaf.effective_start_date AND paaf.effective_end_date
AND paaf.primary_flag = 'Y'
         AND paaf.grade_id = pg.grade_id
         AND paaf.assignment_id = psppf.assignment_id
         AND TRUNC(SYSDATE)  BETWEEN psppf.effective_start_date AND psppf.effective_end_date
         AND psppf.step_id = pspsf.step_id
         AND pspsf.spinal_point_id = psp.spinal_point_id
         AND pspsf1.spinal_point_id = psp1.spinal_point_id
         AND TRUNC(SYSDATE)   BETWEEN pspsf.effective_start_date AND pspsf.effective_end_date
         AND psp.parent_spine_id = pgsf.parent_spine_id
         AND psp1.parent_spine_id = pgsf.parent_spine_id
         AND TRUNC(SYSDATE)  BETWEEN pgsf.effective_start_date AND pgsf.effective_end_date
         AND psp.spinal_point_id = pgrf.grade_or_spinal_point_id
         AND psp1.spinal_point_id = pgrf1.grade_or_spinal_point_id
         AND (psppf.step_id !=  NVL(paaf.special_ceiling_step_id,pgsf.ceiling_step_id)
         AND psppf.auto_increment_flag = 'Y'              
AND (psp1.sequence = (SELECT
MIN(psp2.sequence)
 FROM
per_spinal_points           psp2,
per_spinal_point_steps_f    pspsf2
 WHERE
pspsf.grade_spine_id    = pspsf.grade_spine_id
AND   pspsf2.spinal_point_id  = psp2.spinal_point_id
AND   TRUNC(SYSDATE)  BETWEEN pspsf2.effective_start_date AND pspsf2.effective_end_date
AND   psp2.sequence > psp.sequence))
         OR  psppf.auto_increment_flag = 'N'
         AND psp1.sequence = psp.sequence
         OR  psppf.step_id = NVL(paaf.special_ceiling_step_id,pgsf.ceiling_step_id)
         AND psp1.sequence = psp.sequence)
         AND TRUNC(SYSDATE) BETWEEN pgrf1.effective_start_date AND pgrf1.effective_end_date;

No comments:

Post a Comment

Search This Blog