Step 1:
truncate table DimContact_SCD1
truncate table DimContact_SCD2
btw. DimContact_SCD1 and DimContact_SCD2 have the same structure as DimContact
Step 2:
Step 3:
--SCD1
Update T SET
Address1=S.Address1
,Address2=S.Address2
,City=S.City
,Province=S.Province
,Country=S.Country
,PostalCode=S.PostalCode
FROM DimContact T inner join DimContact_SCD1 S on (T.ContactAlternateKey = S.ContactAlternateKey)
WHERE T.ToDate is NULL
--SCD2
Update T SET
ToDate = convert ( date,?)
FROM DimContact T inner join DimContact_SCD2 S on (T.ContactAlternateKey = S.ContactAlternateKey)
WHERE T.ToDate is NULL
Insert into DimContact (
ContactAlternateKey
,MemberNumber
,IsMember
,FirstName
,LastName
,Address1
,Address2
,City
,Province
,Country
,PostalCode
,Gender
,DriversLicenseType
...
)
SELECT
ContactAlternateKey
,MemberNumber
,IsMember
,FirstName
,LastName
,Address1
,Address2
,City
,Province
,Country
,PostalCode
,Gender
...
FROM DimContact_SCD2
No comments:
Post a Comment