searching columns with LIKE

Results 1 to 2 of 2

Thread: searching columns with LIKE

  1. #1
    Join Date
    Dec 1969

    Default searching columns with LIKE

    i have a form with multiple check boxes, all populated from the database, so i cant hard code this because that list will expand/contract. so each checkbox has a value that corresponds to value that would be in the Client column of a different table. i want to be able to check multiple boxes and have only the recordsets where the client column has a value equal to one of the selected checkboxes. this string below works fine when i select one checkbox, but when i select more than one it says there are no recordsets containing the values. the form is sending a string (SearchString) that may contain something like value1, value2, value3 when 3 boxes are checked. so why isnt this code finding all the recordsets with either value1, value2, or value3 in the string? the % is a wild card that would find and return any sequence of characters in the defined string correct?<BR><BR>&#039;from the form, could contain multiple words, or one.<BR>SearchString = request.form("string") <BR><BR>"SELECT * FROM Jobs WHERE Client LIKE &#039;%"& SearchString &"%&#039; AND JobActivity = &#039;Open&#039; ORDER BY Client ASC"

  2. #2
    Join Date
    Dec 1969

    Default RE: searching columns with LIKE

    You need to split the searchstring and use multiple like predicates.<BR><BR>searchArray = split(request.form("string"),",")<BR>where = "where ("<BR>for i = 0 to ubound(searchArray) <BR>if i &#062; 0 then where = where & " or "<BR>where = where & " client like &#039;%" searchArray(i) & "%&#039;"<BR>next<BR>where = where & ") AND JobActivity = &#039;Open&#039; ORDER BY Client ASC"<BR>sql = "select * from jobs " & where<BR><BR>It&#039;s (of course) untested.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts