• Thank you! Great article!

    I have question about SCD type 2.

    Can we compare all columns in ON clause like this:

    MERGE INTO dbo.Client_SCD2 AS DST

    USING dbo.Client AS SRC

    ON SRC.ID = DST.BusinessKey

    AND DST.ClientName=SRC.ClientName

    AND DST.Country = SRC.Country

    AND DST.Town=SRC.Town

    AND DST.Address1=SRC.Address1

    AND DST.Address2=SRC.Address2

    AND DST.ClientType=SRC.ClientType

    AND DST.ClientSize=SRC.ClientSize

    and then use

    WHEN NOT MATCHED BY SOURCE THEN

    UPDATE SET DST.IsCurrent = 0, DST.ValidTo = @Yesterday

    rather than having this part of code:

    WHEN MATCHED

    AND IsCurrent = 1

    AND (

    ISNULL(DST.ClientName,'') <> ISNULL(SRC.ClientName,'')

    OR ISNULL(DST.Country,'') <> ISNULL(SRC.Country,'')

    OR ISNULL(DST.Town,'') <> ISNULL(SRC.Town,'')

    OR ISNULL(DST.Address1,'') <> ISNULL(SRC.Address1,'')

    OR ISNULL(DST.Address2,'') <> ISNULL(SRC.Address2,'')

    OR ISNULL(DST.ClientType,'') <> ISNULL(SRC.ClientType,'')

    OR ISNULL(DST.ClientSize,'') <> ISNULL(SRC.ClientSize,'')

    )