• Here is an example:

    WHEN

    SOURCE NOT MATCHED THEN

        --DELETE

        UPDATE SET

        d

    .Deleted = 1

    The above code updates the status of the column "deleted" to 1, instead of physically deleting the record.

    If you are doing this,  you need another change at the JOIN condition, to skip the deleted records.

    USING

    OrderInfo AS o

    ON

    (d.OrderNumber = o.OrderNumber AND d.ItemNumber = o.ItemNumber AND d.Deleted = 0)

     

    .