-- Sample only: dedupe using ROW_NUMBER by business key + latest timestamp WITH Ranked AS ( SELECT SourceId, SourceName, SourceUpdatedUtc, ROW_NUMBER() OVER ( PARTITION BY SourceId ORDER BY SourceUpdatedUtc DESC, LoadDtmUtc DESC ) AS rn FROM dbo.Stg_SourceRaw ) SELECT SourceId, SourceName, SourceUpdatedUtc INTO #deduped FROM Ranked WHERE rn = 1; SELECT * FROM #deduped;