Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript SQL Search with multiple keywords

Status
Not open for further replies.

hoosierdoc

Technical User
Oct 17, 2006
3
I have struggled with this all day but finally figured it out. I couldn't find anywhere online where this was discussed so here's my code. It lets you put in unlimited keywords and then do a sql search based on the category and keywords you want. Currently it's an 'OR', but could easily make it in 'AN'. It's ugly code to be sure, but it works. I'm not a programmer, so no crappy comments.
------

cat = request.form("cat")
keyworda = request.form("keyword")

cat = Cstr(cat)
keyworda = Cstr(keyworda)

key = split(keyworda, " ", -1, 1)

For i = 0 to Ubound(key)

blah = blah & "'%" & key(i) & "%' OR " & cat & " Like "

next

xx = len(blah)

blah2 = left(blah, xx-18)

sql = "select * from cat where " & cat & " Like " & blah2
 
Sorry, gotta add one correction. By odd coincidence, most of the categories I had were 8 characters in length. You need to adjust the left() command by the length of the category you are searching on.

Add this code:

y = len(cat) ' underneath where you pull the variable in

And change a line to this:

blah2 = left(blah, xx-10-y) ' this cuts off the right
' amount based on the length
' of your category
 
You might want to have a look at thread222-1116579
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top