Code for implementing intelligent search using ASP

Source: Internet
Author: User

<%
Function autokey (strkey)

Const lngsubkey = 2
Lnglenkey = Len (strkey)

Select case lnglenkey
Case 0' if it is an empty string, go to the error page
Response. Redirect "error.htm"
Case 1' if the length is 1, no value is set
Strnew1 = ""
Strnew2 = ""
Case else 'if the length is greater than 1, the first character of the string starts and the substring with the length of 2 is used as the query condition.

For I = 1 to lnglenkey-(lngSubKey-1)

Strsubkey = mid (strkey, I, lngsubkey)

Strnew1 = strnew1 & "or u_name like '%" & strsubkey & "% '"
Strnew2 = strnew2 & "or u_info like '%" & strsubkey & "% '"
Next
End select

'Get the complete SQL statement
Autokey = "select * From t_sample where u_name like '%" & strkey & "%' or u_info like '%" & strkey & "%'" & strnew1 & strnew2
End Function
%>

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: info-contact@alibabacloud.com 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.