How to use SOUNDEX in Sql Server



SQL Server provides the SOUNDEX function to convert a string into a four-character code based on how the string sounds when spoken. In this article, we will learn how to use SOUNDEX in SQL Server.

The Syntax

The basic syntax of a SOUNDEX is as follows:

SELECT SOUNDEX(string_name);
  • string is the string to convert to a soundex code.

Getting Setup

For this, we will be using docker. This is recommended for more than just using SQL Server. To find how to install docker go here:

Now create a file called docker-compose.yml and add the following.

version: "3.9"
    image: ""
      - 1433:1433
        SA_PASSWORD: "Your_password123"
        ACCEPT_EULA: "Y"

Open a terminal and go to the folder the file is located. Then run the following.

docker-compose up

If you are looking for another good reference, you can check here:

A Simple Example

The soundex is a straight forward function. Let's run a few example to see how different code compare.

SELECT soundex('hello') as res;

We can compare this score to a similar sounding word, "mellow"

SELECT soundex('hello') as res, soundex('mellow') as res2;
res res2
H400 M400

As expected, we see the starting code is different as the two words sound different when sounding out the word.