Populate SCD3 from SCD2.
SELECT * FROM
(
SELECT A.SK,A.EID,A.ST_DT,A.ED_DT FROM EMP2 A
INNER JOIN
(SELECT MAX(ED_DT) AS N_ED_DT , EID FROM EMP2 GROUP BY EID) B
ON A.ST_DT=B.N_ED_DT
UNION ALL
SELECT A.SK,A.EID,A.ST_DT,A.ED_DT FROM EMP2 A
INNER JOIN
(SELECT MAX(ED_DT) AS N_ED_DT , EID FROM EMP2 GROUP BY EID) B
ON A.ED_DT=B.N_ED_DT
) C
ORDER BY C.EID
SELECT * FROM
(
SELECT A.SK,A.EID,A.ST_DT,A.ED_DT FROM EMP2 A
INNER JOIN
(SELECT MAX(ED_DT) AS N_ED_DT , EID FROM EMP2 GROUP BY EID) B
ON A.ST_DT=B.N_ED_DT
UNION ALL
SELECT A.SK,A.EID,A.ST_DT,A.ED_DT FROM EMP2 A
INNER JOIN
(SELECT MAX(ED_DT) AS N_ED_DT , EID FROM EMP2 GROUP BY EID) B
ON A.ED_DT=B.N_ED_DT
) C
ORDER BY C.EID
No comments:
Post a Comment