I have written something that allows people to search library catalogue by author, title and publisher.
I am trying to find a way of allowing the user to specify either a partial or exact match. So far the bit of the SQL statement that is built for the author search is as follows:
AuthorSearch is the string that gets added onto the overall SQL string. Author array is the words that are typed into the search box.
<%
AuthorSearch=""
If UBOUND(AuthorArray,1) >= 0 Then AuthorSearch=AuthorSearch & "("
For i=0 To UBOUND(AuthorArray,1)
AuthorSearch=AuthorSearch & "Catalogue.Author LIKE '%" & AuthorArray(i) & "%'"
If i<UBOUND(AuthorArray,1) Then
AuthorSearch=AuthorSearch & MatchType
End If
Next
If UBOUND(AuthorArray,1) >= 0 Then AuthorSearch=AuthorSearch & ")"
strSQL=strSQL & AuthorSearch
%>
Now I can use some logic to say if the user has specified they want a partial match then to use LIKE '%...%' and if it's an exact match to use ='...'
The problem is if there is an author called Adam Jones and you search for 'Adam' exact match it won't find it because the SQL turns into
...WHERE Author='Adam'
when in fact we need
...WHERE Author='Adam Jones'
What is the best way of matching a whole word but that whole word can appear anywhere in the field?
Thanks very much
Ed
I am trying to find a way of allowing the user to specify either a partial or exact match. So far the bit of the SQL statement that is built for the author search is as follows:
AuthorSearch is the string that gets added onto the overall SQL string. Author array is the words that are typed into the search box.
<%
AuthorSearch=""
If UBOUND(AuthorArray,1) >= 0 Then AuthorSearch=AuthorSearch & "("
For i=0 To UBOUND(AuthorArray,1)
AuthorSearch=AuthorSearch & "Catalogue.Author LIKE '%" & AuthorArray(i) & "%'"
If i<UBOUND(AuthorArray,1) Then
AuthorSearch=AuthorSearch & MatchType
End If
Next
If UBOUND(AuthorArray,1) >= 0 Then AuthorSearch=AuthorSearch & ")"
strSQL=strSQL & AuthorSearch
%>
Now I can use some logic to say if the user has specified they want a partial match then to use LIKE '%...%' and if it's an exact match to use ='...'
The problem is if there is an author called Adam Jones and you search for 'Adam' exact match it won't find it because the SQL turns into
...WHERE Author='Adam'
when in fact we need
...WHERE Author='Adam Jones'
What is the best way of matching a whole word but that whole word can appear anywhere in the field?
Thanks very much
Ed