ASP instance: processing multiple keyword Query code

Source: Internet
Author: User

In web development, I often encounter multiple keyword pairs of a single field query, I usually through a dynamic array to achieve. Of course, a number of keywords are generally used in space or, separated, I this several assumptions with a number of keywords separated by space, the keyword string for keystr, specific code for.

Program code:

The following are the referenced contents:

' Search for keywords
Str= "SELECT * FROM tablename where id>4"
If srhkey<> "" Then
Keyarr=split (Srhkey, "")
J=ubound (Keyarr)
Dim Keystrarr ()
For I=0 to J
If Keyarr (i) <> "" Then
ReDim Preserve Keystrarr (t)
Strfilter= "(Empzw like '%" &keyarr (i) & "% ' or empdep like '%" &keyarr (i) & "%" or empgz like '% "
Strfilter=strfilter&keyarr (i) & "% ' or empWy1 like '%" &keyarr (i) & "% ' or empWy2 like '%" &keyarr (i)
strfilter=strfilter& "% ' or empyq like '%" &keyarr (i) & "% ' or com_name like '%" &keyarr (i) & "%") "
Keystrarr (t) =strfilter
End If
Keystr=join (Keystrarr, "and")
str=str& "and" &keystr
End If

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.