Discussion Locked

Sql and asp (For Combine search)

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I have one form in asp ,
User type some word in it .
I want search in database for them .
my database have one table and one field.
Table name : Catalog
Field name : Select

For example user type this :

"combine Search"+algorithm new
it means :
"Combine Search" AND "Algorithm" OR "new"
in sql means :
from [Catalog] where
[Catalog][Select] like "%Combine Search%" AND
[Catalog][Select] like "%Algorithm%" OR
[Catalog][Select] like "%new%"
I want create this sql .
How can I do?
Thanks ,

3 replies

by r. a. caluste

you need a string parser and the rest is easy.
here is a pseudo code:

myprefix = "[Catalog][Select] like "

get first word (from first letter to next space)
if first letter is equal to " then
j = location of "
k = locate next occurance of " [use instr]
myword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"
else
j = location of first letter
k = locate next occurance of space
myword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"

do until not yet end of mystring
get next word (from first letter to next space)
if first letter is equal to "+" then
myword = myword & " AND "
get next letter
if letter is equal to " then
j = location of "
k = locate next occurance of " [use instr]
myword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"
else
j = location of first letter
k = locate next occurance of space
myword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"
else
myword = myword & " OR "
get next letter
if letter is equal to " then
j = location of " k = locate next occurance of " [use instr]
myword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"
else
j = location of first letter
k = locate next occurance of spacemyword = mid(mystring, j, k - j + 1)
myword = myprefix & "%" & myword & "%"

mysql = "SELECT * from [Catalog] where " & myword

rs.open mysql, myconn

hope this helps.

This discussion is closed to new replies.