;WITH ContactCheck AS
(
SELECT legacyfirstname,
legacylastname,
legacycompanyname,
legacycontactid,
ROW_NUMBER() OVER (PARTITION BY legacylastname, legacyfirstname, legacycompanyname OVER ORDER BY legacylastname) as RN
FROM LegacyContactTable
)
SELECT *
FROM ContactCheck
WHERE RN=1
Lets breakdown that ROW_NUMBER() function works:
You can then alter the code based on your definition of duplicate. You may think that by virtue of having the same first and last name they are a duplicate, or you may think that a duplicate is a record with the same first name, last name, company, email address, and street address. The PARTITION clause would need only be modified accordingly, making for some tidy code.
I would highly recommend
Enjoy!
Post by: James Diamond,