Good morning,
I have a search feature in a site I am working on. The problem is that
the user limited to single word searches, and that if the user only puts
the letter 'a' in the search box the query returns any and all records
that contain the letter 'a'.
In a real word scenario, if they are searching on "mens", they will also
retrieve all those records that contain "women".
Can someone offer up some advice regarding how to limit the search to
the literal string, multiple words, or the presence of a wild card?
I have included a code snipet below.
Thanks in advance for your help.
Regards,
Eric
Set rsSearch = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT style_id, style_name, style_number,
style_price, banner, thumbnail, category_id, category_code,
master_category, master_category.category_name, parent_category,
parent_category.category_name, tblCategory.category_name, module_id " &
_
"FROM qrySearch " & _
"WHERE style_name LIKE '%" & Replace(strSearch,"'","''") & "%' " & _
"OR style_number LIKE '%" & Replace(strSearch,"'","''") & "%' " & _
"OR category_code LIKE '%" & Replace(strSearch,"'","''") & "%'" & _
"OR master_category.category_name LIKE '%" & Replace(strSearch,"'","''")
& "%'" & _
"OR parent_category.category_name LIKE '%" & Replace(strSearch,"'","''")
& "%'" & _
"OR tblCategory.category_name LIKE '%" & Replace(strSearch,"'","''") &
"%'"
rsSearch.CursorLocation = adUseClient
rsSearch.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText