SOUNDEX() Function in SQL Server
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.
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.
This method accepts only one parameter as given below :
- expression : Specified expression to evaluate. It can be a constant, variable, or column.
It returns a four character code in order to evaluate the similarity of two given expressions.
Getting a four character code of the specified expressions which sound similar.
SELECT SOUNDEX('see'), SOUNDEX('sea');
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);
Getting a four character code of the specified expressions which doesn’t sound similar at all.
SELECT SOUNDEX('cs'), SOUNDEX('portal');
Getting a four character code of the specified expressions which are integer.
SELECT SOUNDEX(34), SOUNDEX(45);
So, here no matter what the integer is the code generated will be “0000”.
This function is used to generate a four character code of the specified expressions.