From b1e42c1e3162834a71d18491e495dde091115e35 Mon Sep 17 00:00:00 2001 From: Simon Sabin <1209963+simonsabin@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:39:27 +0000 Subject: [PATCH 1/3] Update documentation for EDIT_DISTANCE function Clarified the definition and behavior of the EDIT_DISTANCE function, including details on maximum distance computation and return values. --- .../functions/edit-distance-transact-sql.md | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/t-sql/functions/edit-distance-transact-sql.md b/docs/t-sql/functions/edit-distance-transact-sql.md index 0671da8c2e5..c0a284327f8 100644 --- a/docs/t-sql/functions/edit-distance-transact-sql.md +++ b/docs/t-sql/functions/edit-distance-transact-sql.md @@ -21,7 +21,7 @@ monikerRange: "=azuresqldb-current || =azuresqldb-mi-current || =fabric-sqldb || [!INCLUDE [preview](../../includes/preview.md)] -Calculates the number of insertions, deletions, substitutions, and transpositions needed to transform one string to another. +Calculates the distance that is the number of insertions, deletions, substitutions, and transpositions needed to transform one string to another. > [!NOTE] > @@ -47,18 +47,23 @@ An alphanumeric expression of character data. *character_expression* can be a co #### *maximum_distance* -The maximum distance that should be computed. *maximum_distance* is an integer. If greater than or equal to zero, then the function returns the actual distance value or a distance value that is greater than *maxiumum_distance* value. If the actual distance is greater than *maximum_distance*, then the function might return a value greater than or equal to *maximum_distance*. If the parameter isn't specified or if *maximum_distance* is negative, then the function returns the actual number of transformations needed. If the value is NULL, then the function returns NULL. +The maximum distance that should be computed. *maximum_distance* is an integer. If greater than or equal to zero, then the function stops calculating the distance when the *maximum_distance* is reached. ## Return value **int** +Returns the distance between the two *character_expressions* using Damerau-Levenshtein algorithm, or *maximum_distance* value if that is smaller. +If any of the inputs is `NULL` then the function returns a `NULL` value. + ## Remarks -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 the number of transformations or *maximum_distance* value. +If the actual distance is greater than *maximum_distance*, then the function might return a value greater than or equal to *maximum_distance*. ## Examples +### Example 1 + The following example compares two words and returns the `EDIT_DISTANCE()` value as a column, named `Distance`. ```sql @@ -75,6 +80,27 @@ WordUK WordUS Distance Colour Color 1 ``` +### Example 2 + +The following example compares two words and returns the `EDIT_DISTANCE()` limited to a maximum value + +```sql +SELECT Source, Target, + EDIT_DISTANCE(Source, Target) AS ActualDistance, + EDIT_DISTANCE(Source, Target,2) AS LimitedDistance +FROM (VALUES('Chocolate', 'Sweets')) compare(Source, Target) ; + +``` + +Returns: + +```output +Source Target ActualDistance LimitedDistance +--------- --------- -------------- --------------- +Chocolate Sweets 8 2 +``` + + For additional examples, see [Example *EDIT_DISTANCE()*](../../relational-databases/fuzzy-string-match/overview.md#example-edit_distance). ## Related content From 9973739613330162e600e5ac50a5c72c2844ad4f Mon Sep 17 00:00:00 2001 From: Simon Sabin <1209963+simonsabin@users.noreply.github.com> Date: Fri, 19 Dec 2025 16:35:19 +0000 Subject: [PATCH 2/3] remove extra line Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/t-sql/functions/edit-distance-transact-sql.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/t-sql/functions/edit-distance-transact-sql.md b/docs/t-sql/functions/edit-distance-transact-sql.md index c0a284327f8..0b3090cb748 100644 --- a/docs/t-sql/functions/edit-distance-transact-sql.md +++ b/docs/t-sql/functions/edit-distance-transact-sql.md @@ -100,7 +100,6 @@ Source Target ActualDistance LimitedDistance Chocolate Sweets 8 2 ``` - For additional examples, see [Example *EDIT_DISTANCE()*](../../relational-databases/fuzzy-string-match/overview.md#example-edit_distance). ## Related content From b697f0c79b24bde6951bb5167ab4dacc215e60cc Mon Sep 17 00:00:00 2001 From: Simon Sabin <1209963+simonsabin@users.noreply.github.com> Date: Fri, 19 Dec 2025 16:35:40 +0000 Subject: [PATCH 3/3] add period Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/t-sql/functions/edit-distance-transact-sql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/t-sql/functions/edit-distance-transact-sql.md b/docs/t-sql/functions/edit-distance-transact-sql.md index 0b3090cb748..cb16ba3d1ba 100644 --- a/docs/t-sql/functions/edit-distance-transact-sql.md +++ b/docs/t-sql/functions/edit-distance-transact-sql.md @@ -82,7 +82,7 @@ Colour Color 1 ### Example 2 -The following example compares two words and returns the `EDIT_DISTANCE()` limited to a maximum value +The following example compares two words and returns the `EDIT_DISTANCE()` limited to a maximum value. ```sql SELECT Source, Target,