devxlogo

Reporting duplicates

Reporting duplicates

Question:
I am having trouble figuring out how to make a report dealing with duplicates. I need to selcet from a table only instances where the first 10 characters of two columns match. For example, I combine the first and last name columns with (||), then I need to take the first 10 letters of the combined column and compare them to the rest of the table to match potential duplicates.

Answer:
Try this and see if it gets you there, or at least gets you started. Play with the length of the second argument in the substring function to see how it changes the columns returned.

create table #dummy (mushedupname Varchar(100))insert #dummy select au_lname+au_fname from authors as mushedupnameselect a.mushedupname, b.mushedupname from #dummy a,  #dummy bwhere substring(a.mushedupname,1,5) = substring(b.mushedupname,1,5)

devx-admin

Share the Post: