
/* Code Fragment 6.21 Bob was promoted to Director on the Computer Center (current version). */

INSERT INTO INCUMBENTS
SELECT '111-22-3333', INCUMBENTS.PCN, GETDATE(), INCUMBENTS.END_DATE
FROM INCUMBENTS, POSITIONS, JOB_TITLES
WHERE SSN = '111-22-3333'
      AND INCUMBENTS.START_DATE <= GETDATE()
      AND INCUMBENTS.END_DATE > GETDATE()
      AND POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE
      AND JOB_TITLE = 'Director, Computer Center'
      AND POSITIONS.START_DATE <= GETDATE()
      AND GETDATE() < POSITIONS.END_DATE

UPDATE INCUMBENTS 
SET END_DATE = GETDATE()
WHERE SSN = '111-22-3333'
      AND PCN <> (SELECT PCN
                  FROM POSITIONS,JOB_TITLES
                  WHERE POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE
                  AND JOB_TITLE = "Director, Computer Center"
                  AND POSITIONS.START_DATE <= GETDATE()
                  AND GETDATE() < POSITIONS.END_DATE)
     AND INCUMBENTS.START_DATE < GETDATE()
     AND INCUMBENTS.END_DATE > GETDATE()

UPDATE INCUMBENTS 
SET PCN = (SELECT PCN
           FROM POSITIONS,JOB_TITLES
           WHERE POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE
           AND JOB_TITLE = "Director, Computer Center"
           AND POSITIONS.START_DATE <= GETDATE()
           AND GETDATE() < POSITIONS.END_DATE)
WHERE SSN = '111-22-3333'
AND START_DATE >= GETDATE()
