• OK.Thank you. This is the whole code i wanted to use:

    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

    WHEN NOT MATCHED BY TARGET THEN

    INSERT (BusinessKey, ClientName, Country, Town, County, Address1, Address2, ClientType, ClientSize, ValidFrom, IsCurrent)

    VALUES (SRC.ID, SRC.ClientName, SRC.Country, SRC.Town, SRC.County, Address1, Address2, ClientType, ClientSize, @Today, 1)

    WHEN NOT MATCHED BY SOURCE THEN

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

    Also i suppose it will have problems with NULL values. And this UPDATE will always go through all records in target table that were deactivated before.