SELECT DISTINCT A.SETID , B.BUDGET_DEPTID , A.POSITION_POOL_ID , A.DESCR FROM PS_POOL_TBL A , PS_DEPT_TBL B WHERE A.SETID = B.SETID AND A.DEPTID = B.DEPTID AND ((A.EFFDT > B.EFFDT AND NOT EXISTS ( SELECT 'X' FROM PS_POOL_TBL A1 WHERE A1.SETID = A.SETID AND A1.DEPTID = A.DEPTID AND A1.POSITION_POOL_ID = A.POSITION_POOL_ID 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_POOL_TBL A2 WHERE A2.SETID = A.SETID AND A2.DEPTID = A.DEPTID AND A2.POSITION_POOL_ID = A.POSITION_POOL_ID AND A2.EFFDT <= B.EFFDT))
|