I’m using the Levenshtein distance from here in my Access Database. Using the functionin a SELECT-Statement works when the function is in the field list. e.g.:
SELECT field, Levenshtein(field, 'Saturday')
FROM table
Where field is a Text-Column (Access-VarChar). Now, I want to use the function in the where-clause as a condition like
SELECT field, Levenshtein(field, 'Saturday') as distance
FROM table
WHERE (Levenshtein(field, 'Saturday') < 5)
But all Access gives me is an error saying “Conflict with types”. Its the same when using distance in the consition instead of Levenshtein(field, 'Saturday').
The levenshtein-function is defined as Public Function Levenshtein(string1 As String, string2 As String) As Long. So what did I do wrong?
I think you have some null values in your table. Could you try this query instead?
(it looks like that a
where field is not nullcondition in your query is not enough, the function is tried to be evaluated anyway)Or you can define your
Levenshteinfunction as(string1 as Variant, string2 as Variant), and make sure you return null if string1 or string2 is null: