
/* Code Fragment 5.12 Provide the salary and position history for all employees, using CASE. */

SELECT S.SSN, AMOUNT, PCN,
"Start Date"=
CASE
	WHEN HISTORY_START_DATE > START_DATE
		THEN HISTORY_START_DATE
		ELSE START_DATE
END,
"End Date"=
CASE
	WHEN HISTORY_END_DATE > END_DATE
		THEN END_DATE
		ELSE HISTORY_END_DATE
END
FROM SAL_HISTORY AS S, INCUMBENTS
WHERE S.SSN = INCUMBENTS.SSN
AND (CASE
	WHEN HISTORY_START_DATE > START_DATE
		THEN HISTORY_START_DATE
		ELSE START_DATE
     END)
<
    (CASE
	WHEN HISTORY_END_DATE > END_DATE
		THEN END_DATE
		ELSE HISTORY_END_DATE
     END)
