Solved

Sql querry using a comma delimited form submission

Posted on 2009-07-13
3
269 Views
Last Modified: 2012-05-07
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.
Scott
0
Comment
Question by:remedy_rider
3 Comments
 
LVL 5

Accepted Solution

by:
dvz- earned 250 total points
ID: 24843495
Scott,
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"

next
 

qSQL = "SELECT * FROM table" & qClause
 

--Then do the query.

Open in new window

0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 250 total points
ID: 24843507
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)

as

	declare strSQL varchar(1000)
 

	set @strSQL = 'Select * from yourtable where yourfield in (' + strSearch + ')'
 

	exec (@strSQL)

Open in new window

0
 

Author Closing Comment

by:remedy_rider
ID: 31602983
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!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about ASP Including Files 6 42
data lookup in Oracle - need suggestions 55 102
SQL Query resolving a string conversion issue 26 38
IP API - need data... 4 12
This article describes some very basic things about SQL Server filegroups.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now