The SQL Server SOUNDEX String Function returns the four-digit Soundex code of the user-specified character expressions and its syntax is
SELECT SOUNDEX(Character_Expression) FROM [Source]
This SQL Soundex function converts any given character’s expression into a four-digit code based on the string sound. It will place the first character from the character_expression as the first digit, and the remaining are numbers. In some cases, it will add 0’s to the end to complete the four-digit code.
SQL SOUNDEX Function Example
The following list of examples will help you to understand the Soundex function.
DECLARE @Str VARCHAR(50) SET @Str = 'SQL Server' SELECT SOUNDEX(@Str) AS SoundText SELECT SOUNDEX('SQL') AS SoundText SELECT SOUNDEX('Sales') AS SoundText SELECT SOUNDEX('Suresh') AS SoundText
In this String method example, we are going to return the SOUNDEX code of the multiple characters expressions, along with the difference. I suggest you refer to the Difference Function article SQL Server to understand the same.
SELECT SOUNDEX('SQL Server') AS Code1, SOUNDEX('SQL') AS Code11, DIFFERENCE('SQL Server', 'SQL') AS Difference1 SELECT SOUNDEX('SQL') AS Code2, SOUNDEX('Suresh') AS Code22, DIFFERENCE('SQL', 'Suresh') AS Difference2 SELECT SOUNDEX('Suresh') AS Code3, SOUNDEX('Srsh') AS Code33, DIFFERENCE('Suresh', 'Srsh') AS Difference3