sqlsql-serversoundex

How does the Soundex function work in SQL Server?


Here's an example of Soundex code in SQL:

SELECT SOUNDEX('Smith'), SOUNDEX('Smythe');
----- ----- 
S530  S530  

How does 'Smith' become S530?

In this example, the first digit is S because that's the first character in the input expression, but how are the remaining three digits are calculated?


Solution

  • Take a look a this article

    The first letter of the code corresponds to the first letter of the name. The remainder of the code consists of three digits derived from the syllables of the word according to the following code:

    • 1 = B, F, P, V
    • 2 = C, G, J, K, Q, S, X, Z
    • 3 = D, T
    • 4 = L
    • 5 = M,N
    • 6 = R

    The double letters with the same Soundex code, A, E, I, O, U, H, W, Y, and some prefixes are being disregarded...

    So for Smith and Smythe the code is created like this:

    S  S   ->   S
    m  m   ->   5
    i  y   ->   0
    t  t   ->   3
    h  h   ->   0
       e   ->   -