title: Finding Potential Duplicates With hyphens or dashes in SQL server 2008
body: <p>I am trying to find potential duplicates in my database.
  Some people might have a duplicate since they have added a "-" into their name or last name (for which ever reason).
  My query currently does not pull people who might have a duplicate of someone with a "-".
  What might be the best way to do this?</p>
  
  <p>This is my query so far</p>
  
  <pre><code>SELECT t1.FirstName, t1.LastName, t1.ID, t2.dupeCount
  FROM Contact t1
  INNER JOIN (
      SELECT FirstName, REPLACE(LastName, '-', ' ') as LastName, COUNT(*) AS dupeCount
      FROM Contact
      GROUP BY FirstName, LastName
      HAVING COUNT(*) &gt; 1
  ) t2 ON ((SOUNDEX(t1.LastName) = SOUNDEX(t2.LastName) 
  OR SOUNDEX(REPLACE(t1.LastName, '-', ' ')) like '%' + SOUNDEX(t2.LastName) + '%'  
  OR SOUNDEX(REPLACE(t2.LastName, '-', ' ')) like '%' + SOUNDEX(t1.LastName) + '%' )
  AND SOUNDEX(t1.FirstName) = SOUNDEX(t2.FirstName))
  ORDER BY t1.LastName, t1.ID
  </code></pre>