My source table looks like below: The records Code can change more than once is indicated within one day
BusinessKey Code CreatedDate
100 ABC 2012-02-25 08:36:38
100 DEF 2012-02-25 08:40:21
100 GIJ 2012-02-25 08:43:21
We need to keep a track of the Code as it changes and our final table should look like:
SurrogateKey BusinessKey Code StartDate EndDate
1 100 ABC 2012-02-25 08:36:38 2012-02-25 08:40:21
2 100 DEF 2012-02-25 08:40:21 2012-02-25 08:43:21
3 100 GIJ 2012-02-25 08:43:21 2100-12-31 00:00:00
I need to load this in SQL Server 2008 R2 using a merge statement