Forum Discussion
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 Microsoft?
Thanks,
Justin
3 Replies
- olafhelperBronze Contributor
Our current SQL server 2017 doesn't have built-in function for calculating Levenshtein distance.No version of SQL Server do have the Levenshtein distance algorythm as build-in function, you have to implement it on your own.
I know Microsoft has that function somewhere.
No, not for SQL Server, only in the Cloud
levenshtein function - Azure Databricks - Databricks SQL | Microsoft Learn
- LainRobertsonSilver 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
- XinyuTanCopper Contributor