DIFFERENCE (Transact-SQL)
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
This function returns an integer value measuring the difference between the SOUNDEX() values of two different character expressions.
Transact-SQL syntax conventions
Syntax
DIFFERENCE ( character_expression , character_expression )
Note
To view Transact-SQL syntax for SQL Server 2014 (12.x) and earlier versions, see Previous versions documentation.
Arguments
character_expression
An alphanumeric expression of character data. character_expression can be a constant, variable, or column.
Return Types
int
Remarks
DIFFERENCE
compares two different SOUNDEX
values, and returns an integer value. This value measures the degree that the SOUNDEX
values match, on a scale of 0 to 4. A value of 0 indicates weak or no similarity between the SOUNDEX values; 4 indicates strongly similar, or even identically matching, SOUNDEX values.
DIFFERENCE
and SOUNDEX
have collation sensitivity.
Examples
The first part of this example compares the SOUNDEX
values of two very similar strings. For a Latin1_General collation, DIFFERENCE
returns a value of 4
. The second part of the example compares the SOUNDEX
values for two very different strings, 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)
See Also
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho