Delen via


SOUNDEX (Transact-SQL)

Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings.

Topic link iconTransact-SQL Syntax Conventions

Syntax

SOUNDEX (character_expression )

Arguments

  • character_expression
    Is an alphanumeric expression of character data. character_expression can be a constant, variable, or column.

Return Types

varchar

Remarks

SOUNDEX converts an alphanumeric string to a four-character code to find similar-sounding words or names. The first character of the code is the first character of character_expression and the second through fourth characters of the code are numbers. Vowels in character_expression are ignored unless they are the first letter of the string. String functions can be nested.

Examples

The following example shows the SOUNDEX function and the related DIFFERENCE function. In the first example, the standard SOUNDEX values are returned for all consonants. Returning the SOUNDEX for Smith and Smythe returns the same SOUNDEX result because all vowels, the letter y, doubled letters, and the letter h, are not included.

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

Here is the result set.

----- ----- 
S530  S530  

(1 row(s) affected)

The DIFFERENCE function compares the difference of the SOUNDEX pattern results. The following example shows two strings that differ only in vowels. The difference returned is 4, the lowest possible difference.

-- Using DIFFERENCE
SELECT DIFFERENCE('Smithers', 'Smythers');
GO

Here is the result set.

----------- 
4           

(1 row(s) affected)

In the following example, the strings differ in consonants; therefore, the difference returned is 2, the greater difference.

SELECT DIFFERENCE('Anothers', 'Brothers');
GO

Here is the result set.

----------- 
2           

(1 row(s) affected)

See Also

Reference