Related Articles

# SOUNDEX() Function in SQL Server

• Last Updated : 05 Jan, 2021

SOUNDEX() function :
This function in SQL Server is used to return a four character code in order to evaluate the similarity of two specified expressions.

Features :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

• This function is used to find a four character code of two specified expressions.
• This function accepts expression.
• The expression can be a constant, variable or column.
• This function converts the stated expression to a four character code which is based on how the specified string sounds when its spoken.

Syntax :

`SOUNDEX(expression)`

Parameter :
This method accepts only one parameter as given below :

• expression : Specified expression to evaluate. It can be a constant, variable, or column.

Returns :
It returns a four character code in order to evaluate the similarity of two given expressions.

Example-1 :
Getting a four character code of the specified expressions which sound similar.

`SELECT SOUNDEX('see'), SOUNDEX('sea');`

Output :

`S000`

Example-2 :
Using SOUNDEX() function with variables and getting a four character code.

```DECLARE @exp1 VARCHAR(15);
DECLARE @exp2 VARCHAR(15);
SET @exp1 = 'sum';
SET @exp2 = 'some';
SELECT SOUNDEX(@exp1), SOUNDEX(@exp2);```

Output :

`S500`

Example-3 :
Getting a four character code of the specified expressions which doesn’t sound similar at all.

`SELECT SOUNDEX('cs'), SOUNDEX('portal');`

Output :

`P634`

Example-4 :
Getting a four character code of the specified expressions which are integer.

`SELECT SOUNDEX(34), SOUNDEX(45);`

Output :

`0000`

So, here no matter what the integer is the code generated will be “0000”.

Application :
This function is used to generate a four character code of the specified expressions.

My Personal Notes arrow_drop_up