SQL Standard

SQL Server Difference

The difference in SQL Server allows you to calculate the difference in the soundex() values between different character expressions.

What is Soundex?

The soundex value in SQL Server determines the similarity between two strings when spoken in English.

The soundex() function in SQL Server returns a soundex code that can calculate how similar two strings sounds when spoken.

Learn more about SQL Server soundex.

SQL Server Difference

The function syntax is as shown:

DIFFERENCE ( character_expression , character_expression );

 

Extract: Microsoft SQL Server.

Example 1

The following example shows how to calculate the soundex difference between two similar strings.

SELECT SOUNDEX('Hello'), SOUNDEX('Hello'), DIFFERENCE('Hello','Hello');

The above query returns a difference of 4. This is the least possible difference value.

Example 2

For two completely different strings, the difference function should return 0.

An example is as shown:

SELECT SOUNDEX('Hello'), SOUNDEX('Tomato'), DIFFERENCE('Hello','Tomato');

The code above should return a difference value of 0. This is the highest difference value.

Example 3

You can also have a medium difference as shown:

SELECT SOUNDEX('tomato), SOUNDEX('potato'), DIFFERENCE('potato','tomato');

The above should return a difference value of 2.

Closing

This tutorial gives a high-level overview of how the difference function works in SQL Server. We recommend exploring the documentation to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list