Use SQL statement 4 in ASP: Union statement

Source: Internet
Author: User
Use SQL statement 4 in ASP: Union statement
ArticleSource:
The SQL statements we have mentioned so far are relatively simple. If we can use standard recordset for loop query, these statements can also meet more complex requirements. However, why do we have to stick to the basic level of simplicity? You can add other symbols, such as and, or, and not, to complete more powerful functions.

The following SQL statement is used as an example:

SQL = "select c_firstname, c_lastname, c_email from customers where c_email is

Not null and c_purchase = '1' or c_purchase = '2' and c_lastname like

'A % '"

As far as your current knowledge of SQL is concerned, the above examples are not difficult to explain, but the above statements do not clearly show you how condition statements are glued into a single SQL statement.

Multi-line statements

When SQL statements are hard to understand, you may want to break down the entire statement into multiple rows.CodeThen, the component of the query statement is gradually added based on the existing variable and stored in the same variable:

SQL = "select c_firstname, c_lastname, c_emailaddress, c_phone"

SQL = SQL & "from MERs"

SQL = SQL & "where c_firstname like 'a % 'and c_emailaddress not null"

SQL = SQL & "order by c_lastname, c_firstname"

In the last sentence, the SQL variable contains the following complete SELECT statement:

"Select c_firstname, c_lastname, c_emailaddress, c_phone from MERs

Where c_firstname like 'a % 'and c_emailaddress no null order by c_lastname,

C_firstname"

The entire sentence is obviously much read after being decomposed! During debugging, you may be more comfortable typing a few more charactersProgramBetter read. However, you must remember that you need to add spaces before or after the quotation marks are closed to ensure that the strings are not joined together.

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.