In PeopleSoft, following can be the queries to fetch the Direct & Indirect reportees for a Manager.
SELECT A.EMPLID , A.EMPL_RCD , A.POSITION_NBR
FROM PS_JOB_CURR_VW A, PS_PERSON_NAME B WHERE A.EMPLID=B.EMPLID and a.POSITION_NBR<>' ' and a.EMPLID in ( select EMPLID from ( select a.EMPLID , POSITION_NBR , REPORTS_TO , EMPL_STATUS from PS_JOB a WHERE a.effdt = ( SELECT MAX(EFFDT) FROM PS_JOB WHERE EMPLID=A.EMPLID AND EMPL_RCD=A.EMPL_RCD AND EFFDT<=sysdate) AND A.EFFSEQ = ( SELECT MAX(EFFSEQ) FROM PS_JOB WHERE EMPLID = A.EMPLID AND EMPL_RCD = A.EMPL_RCD AND EFFDT = A.EFFDT) AND position_nbr <> reports_to AND reports_to <> ' ' and EMPL_STATUS = 'A' ) start with
REPORTS_TO = ( select POSITION_NBR from PS_JOB A1 , PSOPRDEFN B1 where A1.EMPLID = B1.EMPLID
and A1.EFFDT = ( select max(EFFDT) from PS_JOB where EMPLID = A1.EMPLID and EMPL_RCD = A1.EMPL_RCD and EFFDT <= sysdate) and A1.EFFSEQ = ( select max(EFFSEQ) from PS_JOB where EMPLID = A1.EMPLID and EMPL_RCD = A1.EMPL_RCD and EFFDT = A1.EFFDT and A1.HR_STATUS='A') and OPRID = 'USER_OPRID' ) connect by nocycle prior POSITION_NBR=REPORTS_TO and POSITION_NBR <> REPORTS_TO and REPORTS_TO <> ' ' and EMPL_STATUS = 'A'); |
- With passing of Manager’s EMPLID
select a.*
from PS_DIR_REPORTS_VW3 a where a.POSITION_NBR<>' ' and a.REPORTS_TO<>' ' and level>1 start with a.EMPLID='12345'
connect by nocycle prior a.POSITION_NBR=a.REPORTS_TO
ORDER BY LEVEL; |