Sql querry using a comma delimited form submission

Hello, I have a form that submits a key word and searches through all my fields within a table. I use the % wildcards at the begining and end which works fine. It was brought up that they want the search to take comma delimited words and find all related content. Right now if you do that it's trying to find the whole string example: (eyes,toes,feet) it will not find anything, but it will find something if you just put in "eyes". what's the best suggestion for setting up a form and an sql query to get the results? thanks in advance!

P.S. I have this coded in Classic asp.
Who is Participating?
dvz-Connect With a Mentor Commented:
I'm not fluent with ASP atm, but what about taking the input and splitting it by the comma into an array, and building a where clause from that.  From there, I'd attach that to an SQL query string...i.e. something like the following code.

forgive any syntax errors.

strInput = 'eyes,toes,feet'
arrSearch = split(strInput , ",")
for ndx = 0 to ubound(arrSearch)
  qClause = qClause & " where field_name like '%" & arrSearch(ndx) & "%'"
  if ndx < ubound(arrSearch) - 1 
  then qClause = qClause & " and"
qSQL = "SELECT * FROM table" & qClause
--Then do the query.

Open in new window

ralmadaConnect With a Mentor Commented:
I would suggest dynamic SQL. Maybe you can put the search algortyhm in a stored procedure and call it like this:
exec Search_procedure '''eyes'',''toes'',''feet''' (Please note that quotes separating the words are two single quotes not a double quote)

create procedure Search_procedure 
strSearch varchar(1000)
	declare strSQL varchar(1000)
	set @strSQL = 'Select * from yourtable where yourfield in (' + strSearch + ')'
	exec (@strSQL)

Open in new window

remedy_riderAuthor Commented:
I awarded both equal, hoping one will work for me. I'm still getting fimiliar with Stored Procedures so i'm not sure how to set that up. I'll give them both a try. thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.