title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | dev_langs | monikerRange | |
---|---|---|---|---|---|---|---|---|---|---|---|
EDIT_DISTANCE_SIMILARITY (Transact-SQL) |
EDIT_DISTANCE_SIMILARITY calculates a similarity value ranging from 0 (indicating no match) to 100 (indicating full match). |
MikeRayMSFT |
mikeray |
abhtiwar, wiassaf, randolphwest |
01/15/2025 |
sql |
t-sql |
reference |
|
=azuresqldb-current || =fabric |
[!INCLUDE asdb-fabricsqldb]
[!INCLUDE preview]
Calculates a similarity value ranging from 0 (indicating no match) to 100 (indicating full match).
EDIT_DISTANCE_SIMILARITY (
character_expression,
character_expression
)
An alphanumeric expression of character data. character_expression can be a constant, variable, or column. The character expression cannot be of type varchar(max) or nvarchar(max).
int
This function implements the Damerau-Levenshtein 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
.
The following example compares two words and returns the EDIT_DISTANCE_SIMILARITY()
value as a column, named Distance
.
SELECT 'Colour' AS WordUK,
'Color' AS WordUS,
EDIT_DISTANCE_SIMILARITY('Colour', 'Color') AS Distance;
Returns:
WordUK WordUS Distance
------ ------ -----------
Colour Color 83
For additional examples, see Example EDIT_DISTANCE_SIMILARITY().