Nóta
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as shíniú isteach nó eolairí a athrú.
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as eolairí a athrú.
Applies to:
SQL Server 2025 (17.x)
Azure SQL Database
Azure SQL Managed Instance
SQL analytics endpoint in Microsoft Fabric and Warehouse in Microsoft Fabric
SQL database in Microsoft Fabric
Calculates a similarity score between two strings based on their edit distance. The score ranges from 0 (no similarity) to 100 (an exact match).
Note
EDIT_DISTANCE_SIMILARITYis generally available starting with SQL Server 2025 (17.x) CU11. On earlier SQL Server 2025 builds, the function is in preview. If it isn't enabled by default on your build, enable PREVIEW_FEATURES by setting it toON.EDIT_DISTANCE_SIMILARITYis available in Azure SQL Managed Instance with the SQL Server 2025 or Always-up-to-date update policy.
Syntax
EDIT_DISTANCE_SIMILARITY (
character_expression
, character_expression
)
Arguments
character_expression
An alphanumeric expression of character data. character_expression can be a constant, variable, or column. The character expression can't be of type varchar(max) or nvarchar(max).
Return value
int
Remarks
This function implements the Damerau-Levenshtein (Optimal String Alignment) algorithm. If any of the inputs is NULL then the function returns a NULL value. Otherwise, the function returns an integer value from 0 to 100. The similarity value is computed as (1 - (edit_distance / greatest(len(string1), len(string2)))) * 100.
Examples
A. Calculate edit distance similarity between two words
The following example compares two words and returns the EDIT_DISTANCE_SIMILARITY() value as a column, named Similarity.
SELECT 'Colour' AS WordUK,
'Color' AS WordUS,
EDIT_DISTANCE_SIMILARITY('Colour', 'Color') AS Similarity;
Here's the result set.
WordUK WordUS Similarity
------ ------ -----------
Colour Color 83
For more examples, see the Examples section in the Fuzzy string matching overview.