Any suggestions? Export (0) Print
Expand All

DIFFERENCE (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008) yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns an integer value that indicates the difference between the SOUNDEX values of two character expressions.

Topic link icon Transact-SQL Syntax Conventions


DIFFERENCE ( character_expression , character_expression )
-- Azure SQL Data Warehouse and Parallel Data Warehouse
DIFFERENCE (character_expression ,character_expression )

character_expression

Is an alphanumeric expression of character data. character_expression can be a constant, variable, or column.

The integer returned is the number of characters in the SOUNDEX values that are the same. The return value ranges from 0 through 4: 0 indicates weak or no similarity, and 4 indicates strong similarity or the same values.

DIFFERENCE and SOUNDEX are collation sensitive.

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

-- Returns a DIFFERENCE value of 4, the least possible difference.
SELECT SOUNDEX('Green'), SOUNDEX('Greene'), DIFFERENCE('Green','Greene');
GO
-- Returns a DIFFERENCE value of 0, the highest possible difference.
SELECT SOUNDEX('Blotchet-Halls'), SOUNDEX('Greene'), DIFFERENCE('Blotchet-Halls', 'Greene');
GO

Here is the result set.

----- ----- ----------- 
G650  G650  4           

(1 row(s) affected)

----- ----- ----------- 
B432  G650  0           

(1 row(s) affected)

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

-- Returns a DIFFERENCE value of 4, the least possible difference.
SELECT SOUNDEX('Green'), SOUNDEX('Greene'), DIFFERENCE('Green','Greene');
GO
-- Returns a DIFFERENCE value of 0, the highest possible difference.
SELECT SOUNDEX('Blotchet-Halls'), SOUNDEX('Greene'), DIFFERENCE('Blotchet-Halls', 'Greene');
GO

Here is the result set.

----- ----- ----------- 
G650  G650  4           

(1 row(s) affected)

----- ----- ----------- 
B432  G650  0           

(1 row(s) affected)

Community Additions

ADD
Show:
© 2016 Microsoft