DIFFERENCE() Function in SQL Server

The DIFFERENCE() function compares two different SOUNDEX values, and return the value of the integer. This value measures the degree that the SOUNDEX values match, on a scale of 0 to 4. A value of 0 indicates a weak or no similarity between the SOUNDEX values; 4 indicates that the SOUNDEX values are extremely similar, or even identical.

Syntax :

DIFFERENCE(string, string)

Parameter : This method accepts two-parameters as mentioned above and described below –

  • string, string –
    It is an alphanumeric expression of character data. It can be a constant, variable, or column.

Returns : It returns an integer value measuring the difference between the SOUNDEX() values of two different string.

Example-1 :
Using DIFFERENCE() function with similar SOUNDEX() values.

SELECT SOUNDEX('poor') soundex_poor, SOUNDEX('pour') soundex_pour, 
DIFFERENCE('poor', 'pour') similarity;

Output :

soundex_poor soundex_pour similarity
P600 P600 4

Example-2 :
Returns a DIFFERENCE value of 3, the less possible difference.

SELECT SOUNDEX('GeeksForGeeks'), SOUNDEX('GeeksOfGeeks'),
DIFFERENCE('GeeksForGeeks', 'GeeksOfGeeks');

Output :


Example-3 :
Returns a DIFFERENCE value of 2, the medium possible difference.

SELECT SOUNDEX('GeeksForGeeks') soundex_GeeksForGeeks, SOUNDEX('GFG') soundex_GFG,
DIFFERENCE('GeeksForGeeks', 'GFG') similarity;

Output :

soundex_GeeksForGeeks soundex_GFG similarity
G216 G120 2

Example-4 :
Returns a DIFFERENCE value of 0, the highest possible difference.

SELECT SOUNDEX('javascript') soundex_javascript, SOUNDEX('c#') soundex_c#,
DIFFERENCE('javascript', 'c#') similarity;

Output :

soundex_javascript soundex_c# similarity
J126 C000 0
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.