2

我正在使用 SQL Server 2008 并且需要编写一个查询,该查询应该返回一条记录,说明ABCDEFGH用户是否输入了诸如ABCD-EFGHor之类的搜索字符串ABDEFGH(即类似的记录)。

我将如何做到这一点?

4

1 回答 1

2

you need to employ some sort of editDistance algorithm i.e Levenshtein distance ,Jaro–Winkler distance to calculate the difference between 2 strings.

look at this thread for Levenshtein distance implemented as udf

Levenshtein distance in T-SQL

you will use the UDF like this (just an example)

SELECT * FROM dbo.myTable
WHERE   dbo.editDistance(mycol,@SearchString)<2
于 2012-09-13T22:57:41.587 回答