Forum Discussion
XinyuTan
Dec 13, 2023Copper Contributor
Levenshtein Distance Function
Our current SQL server 2017 doesn't have built-in function for calculating Levenshtein distance. I know Microsoft has that function somewhere. How can we obtain such built-in function from Microsof...
LainRobertson
Silver Contributor
Hey, Justin.
It doesn't exist in SQL Server (deliberately excluding Master Data Services), but you can achieve a similar outcome using DIFFERENCE:
- DIFFERENCE (Transact-SQL) - SQL Server | Microsoft Learn
- How to add Percentage of similar compare two string ? - Microsoft Q&A
You could look at authoring your own SQL CLR-based function using the Spark library, but this isn't particularly portable since you cannot add CLR-based functions to the more affordable Azure SQL options (only Azure SQL MI can handle CLR functions):
- Create CLR Functions - SQL Server | Microsoft Learn
- It's just SQL: CLR in Azure SQL Database Managed Instance | Microsoft Learn
- Functions.Levenshtein(Column, Column) Method (Microsoft.Spark.Sql) - .NET for Apache Spark | Microsoft Learn
Cheers,
Lain
XinyuTan
Dec 14, 2023Copper Contributor