Problem:
How to compare two words and get the difference of the string text?
Solution:
This is a string function which
gives out a four-character output based on the input string.
Based on the sounding of a name,
address, or an object this will assign a value and similar pronunciations get
the same result.
The first character of the output
is always the first word of the input with Capital case and the rest three
characters are based on the sounding of how they are pronounced.
The next thing we can do is to
compare the input; it can be compared using difference function to show how SOUNDEX
values of two characters looks like.
Returns an integer value as output, lowest is 4, which means it is
close to the sound of the input and compared value and 0 is the highest and
which means they don’t sound similar.
Example:
Example 1: In this example I would
like to show you how SOUNDEX works on two names of the same pronounce and spell
differently.
SELECT [Fname]
,SOUNDEX([Fname]) as sounding
,[Lname]
,[Gender]
FROM [dbo].[Subject]
OUTPUT:
Fname
|
sounding
|
Lname
|
Gender
|
Steven
|
S315
|
paul
|
male
|
Stephen
|
S315
|
xill
|
male
|
As you can
see Steven and Stephen are spelled differently but the SOUNDEX values are same.
Example 2:
In this example I would like to show to compare the soundex codes of different
words
SELECT [Fname]
,DIFFERENCE([Fname],LNAME) as sounding
,[Lname]
,[Gender]
FROM [dbo].[Subject]
The lowest is 4, which means it is close to the sound of the input and
compared value and 0 is the highest and which means they don’t sound similar.
OUTPUT:
Fname
|
sounding
|
Lname
|
Gender
|
Steven
|
0
|
paul
|
male
|
Stephen
|
4
|
Stephan
|
male
|
So as we can see the first name last name of Steven and paul
doesn’t sound similar the difference is 0 and the Second row has an output of 4
which means they are sounding same almost.
0 comments:
Post a Comment