SOUNDEX()

This function accepts a string and converts it to a four-character code based on how the string sounds when it is spoken. The first character is the first letter of the phrase. Vowels are omitted unless the first letter of the phrase is a vowel and the other three characters represent the rest of the phrase. It add zeros at the end of the result code if necessary to make a four-character code.

Syntax of this function is

SOUNDEX(input_string);

DIFFERENCE()

This function returns an integer value measuring the difference between the SOUNDEX() values of two strings. It evaluates two expressions and assigns a value between 0 and 4. 0 being little to no similarity and 4 representing the same or very similar phrases. This value is derived from the number of characters in the SOUNDEX of each phrase that are the same.

Example

This example uses the SOUNDEX() function to find code of string.

SELECT SOUNDEX('TOO') S2
SELECT SOUNDEX('TO') S1

/* Output */
T000
T000

The example that compares the difference in SOUNDEX() values.

SELECT SOUNDEX('TOO') S1, SOUNDEX('TO') S2, DIFFERENCE('TOO', 'TO') D1;

Reference

SQL Server SOUNDEX() Function