The simplest multi-query solution for ASP-application techniques

Source: Internet
Author: User
The simplest solution for multiple queries

Objective
We often encounter multiple query problems, and long SQL statements are often confused. In particular, when the client part of the query conditions, such as the ordinary method will be even more difficult.
The following ingeniously uses the identity of the "where 1=1" (in fact many, let it be true) to solve the problem.

[Text Summary]

' Subject Information title
' Company name to release information
' Content to post information
' Address Company
' Infomation Company profile
' Note related
The above values are submitted by Form, and then the corresponding values are obtained by: Subject=trim (Request.Form ("subject")).

<%
' This function is critical! ---------------------------
Function SQL (A,B,SQLS)
If b<> "then" if the client does not submit this value, the corresponding SQL statement is not generated.
Sqls=sqls & "and" & A & "Like '%" & B & "%"
End If
Sql=sqls
End Function
'-----------------Call the database
Set conn=server.createobject ("ADODB. Connection ")
Dbpath=server.mappath ("/database/mydb.mdb")
Conn.Open "Driver={microsoft Access driver (*.mdb)};p wd=;d bq=" & DBPath
Set rs=server.createobject ("ADODB. Recordset ")
Sqls= "SELECT * FROM MyTable where 1=1"
' The following calls the above function, which can be called very many (theoretically arbitrary)
Sqls=sql ("Subject", Subject,sqls)
Sqls=sql ("Company", Company,sqls)
Sqls=sql ("Content", Content,sqls)
Sqls=sql ("Address", ADDRESS,SQLS)
Sqls=sql ("infomation", Infomation,sqls)
Sqls=sql ("note", Note,sqls)
Sqls=sqls & "ORDER BY id DESC"
Rs.Open sqls,conn,3,2
%>

Conclusion
If there are no key function functions of SQL (A,B,SQLS), we can imagine how much it takes to judge one sentence after another!

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.