Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with dynamic Database Search

Author  Topic 

sirmanix
Starting Member

9 Posts

Posted - 2001-09-19 : 08:54:50
hi,
I have the following code to make an AND query for as many words a user enters in a Form. If I enter one word it works fine. with 2 or more than 2 words it doesnt work properly and always ignores the 2nd word the user has entered in the form.
What did I do wrong?

thanks for the help

Words=request.form("search")
Words = split(Input, " ")
count=Ubound(Words)

'-- if user just entered one word do this--
if count=0 then
query="'%" &Words(i)& "%'"
else
'-- if user entered more than 1 word --
for i=0 to count
'-- while end of array make query with AND
if i<count then
query=query & "'%" &Words(i)& "%'"&" AND "
else
'----end of array so don't add AND at ending.
query=query & "'%" &Words(i)& "%'"
end if
i=i+1
next

end if
'-- now make sql query ----
SQL="SELECT * FROM [Artikle] WHERE ([text] LIKE "& search &") ORDER BY time"

   

- Advertisement -