2

I am using SQL Server 2008 and need to write a query that should return a record of ABCDEFGH if a user enters a search string such as ABCD-EFGH or ABDEFGH etc (i.e. records that are similar to).

How would I accomplish that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DNR
  • 3,706
  • 14
  • 56
  • 91
  • Maybe you want to look at the built-in function `DIFFERENCE`: http://msdn.microsoft.com/en-us/library/ms188753.aspx I am not sure it would help you in this specific case, but it might do the trick. – Johan Sep 14 '12 at 08:16

1 Answers1

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
Community
  • 1
  • 1
ClearLogic
  • 3,616
  • 1
  • 23
  • 31