“Sound Like” Strings

Two days back, a colleague of mine asked How can he retrieve all rows which have similar employee names.

The situation, there are two tables/Excel sheets he has got from two different sources for the same set of employees. he needs to extract some information from both. the employee name column is the key to identity each one of these employees. the challenge here, employee name is not exactly the same in the two files.

The first solution jumped on the table is similar names. SQL Server provides us with some functions which will help us to achieve this task such as SOUNDEX() and DIFFERENCE().

Here is an example, assume there is a table like below

This table contains some of my friends’ names. as this table shows I have 5 friends share similar names with “Mhmd” letters but with different form for each one of them.

Now I want to write T-SQL query which should give me all friends whose name sounds similar “Mhmd”.

I wrote this query

SELECT     FriendFisrtName, FriendLastName
FROM       MyFriends
WHERE      SOUNDEX('Mhmd') = SOUNDEX(FriendFisrtName)

And I got this result set

Hope this helps…

Shout it kick it on DotNetKicks.com Retweet

About these ads

2 Comments

  1. Pingback: DotNetShoutout

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s