Home > Functions and DMVs, SQL Queries, SQL Server, T-SQL > Using string function DIFFERENCE()

Using string function DIFFERENCE()

The function “Difference” is used to check the similarity between two string based on its sound. This function internally uses the sound- ex algorithm to fetch the differnce between two strings. The return value is an integer in the range of 0 to 4. “0” indicates no similarity and  value 4 indicates high similarity.  

In the first part of the following example, the SOUNDEX values of two very similar strings are compared, and DIFFERENCE returns a value of 4. In the second example, the SOUNDEX values for two very different strings are compared, and  returns a value of 1.  

SELECT SOUNDEX(‘SYSTEM’), SOUNDEX(‘SISTEM’) ,DIFFERENCE(‘SYSTEM’,‘SISTEM’) 

O/P:            S235                  S235                         4 

 
 

  

SELECT  SOUNDEX(‘GREEN’), SOUNDEX(‘BLUE’) ,DIFFERENCE(‘GREEN’,‘BLUE’)
 O/P:             G652                B400                         1

  

  

  

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: