0

Possible Duplicate:
Fuzzy matching using T-SQL

Let's assume i have table of my clients: firstName,MiddleName,LastName . I want to select all the records where LastName equals to or is near the same as 'Robert'. By near the same I mean that maximum of 25% of characters in entered text differ from the some value in DB. Is it possible to achieve that in Microsoft SQL sver 2008?

Why do I need this? Let's say user entered 'peterdson' instead of 'peterson'. I want to display user message that suggests the more relevant result.

Community
  • 1
  • 1
seeker
  • 3,255
  • 7
  • 36
  • 68
  • 1
    I don't know if SQL has native functionality for comparing strings like that, but it sounds like you want to implement the Levenshtein Distance Algorithm for comparing two strings: http://en.wikipedia.org/wiki/Levenshtein_distance – David Sep 28 '12 at 14:17
  • This algorithm may be used to compare 'distance' beetween two strings, but the problem I want to solve is to find all string in database table column that has distance no more then N. – seeker Sep 28 '12 at 14:22
  • And in order to find those strings, you'll need to compare them. You'd then filter the records based on the results of the comparison (where distance <= N). – David Sep 28 '12 at 14:24
  • That's time consuming - maybe I'm wrong but in that way full table scan will take place. But thank you on this anyway. If there would be any other ways, I will be very glad to read about them, – seeker Sep 28 '12 at 14:27
  • I don't really see a way to do a complex string comparison without doing a table scan, honestly. Indexes really aren't that "smart." And there definitely isn't a way to get the results of a string comparison without comparing strings. Hopefully there's native SQL functionality that can help because it will be pretty well optimized (otherwise you'll have to develop it), but it would still be a comparison at a fundamental level. – David Sep 28 '12 at 14:36

0 Answers0