SELECT DISTINCT B.SETID ,B.BUDGET_DEPTID ,A.POSITION_NBR ,A.DESCR FROM PS_POSITION_DATA A , PS_DEPT_TBL B WHERE B.SETID=( SELECT Z.SETID FROM PS_SET_CNTRL_REC Z WHERE Z.SETCNTRLVALUE=A.BUSINESS_UNIT AND Z.RECNAME='DEPT_TBL') AND B.DEPTID=A.DEPTID AND ((A.EFFDT > B.EFFDT AND NOT EXISTS ( SELECT 'X' FROM PS_POSITION_DATA A1 WHERE A1.POSITION_NBR = A.POSITION_NBR AND B.SETID = ( SELECT Z1.SETID FROM PS_SET_CNTRL_REC Z1 WHERE Z1.SETCNTRLVALUE = A1.BUSINESS_UNIT AND Z1.RECNAME = 'DEPT_TBL') AND A1.DEPTID = A.DEPTID AND A1.EFFDT < A.EFFDT AND A1.EFFDT > B.EFFDT) AND NOT EXISTS ( SELECT 'X' FROM PS_DEPT_TBL B1 WHERE B1.SETID = B.SETID AND B1.DEPTID = B.DEPTID AND B1.EFFDT < A.EFFDT AND B1.EFFDT > B.EFFDT)) OR A.EFFDT = ( SELECT MAX(A2.EFFDT) FROM PS_POSITION_DATA A2 WHERE A2.POSITION_NBR = A.POSITION_NBR AND B.SETID = ( SELECT Z2.SETID FROM PS_SET_CNTRL_REC Z2 WHERE Z2.SETCNTRLVALUE = A2.BUSINESS_UNIT AND Z2.RECNAME = 'DEPT_TBL') AND A2.DEPTID = A.DEPTID AND A2.EFFDT <= B.EFFDT))
|