Hey there, I've been struggling a bit with my dim_employee ETL design. Basically, the source table from the HR system has from/to dates already. When I used the start/end date logic for the SCD transformation wizard, I started having a lot of conflicts because I need to track history on quite a few columns, including the dates. Anyway, what I'm playing with now and think will work is to stage the data first to look for changes on non-current flag'd records and union it to a check to see if there are new records. I've just now come up with this idea after a couple of days of reading/searching and wanted to see if anyone had any thoughts/review notes. Without constraining to only new records in the transformation, every execution adds records irrespective of whether there are changes (I've mapped data types a dozen or so times and actually created the dim table as a replica of the origin table so I'm pretty sure it's not a stray data type). Any thoughts would be much appreciated!
SELECT e.employeeid, e.lastname, e.firstname, e.badgenum, e.status_type, e.employee_type, e.division, e.fromdate, e.todate
FROM employeesource e
JOIN dbo.dim_employee X ON X.employeeid=e.employeeid AND X.valid_from_date=E.fromdate AND X.current_flag='Y'
WHERE EXISTS (SELECT X.employeeid, X.lastname, X.firstname, X.badgenum, X.status_type, X.employee_type, X.division, X.valid_to_date
EXCEPT
SELECT e.employeeid, e.lastname, e.firstname, e.badgenum, e.status_type, e.employee_type, e.division, e.todate
)
UNION ALL
SELECT e.employeeid, e.lastname, e.firstname, e.badgenum, e.status_type, e.employee_type, e.division, e.fromdate, e.todate
FROM employeesource e
WHERE NOT EXISTS
(SELECT 1
FROM dbo.dim_employee X
WHERE X.employeeid=e.employeeid AND X.valid_from_date=E.fromdate --AND X.current_flag='Y'
)