Use SQL statement 2 in ASP: use where clause to set query Conditions

Source: Internet
Author: User
Use SQL statement 2 in ASP: use where clause to set query Conditions
Source: dns99.cn

Sometimes retrieving all the database records may meet your requirements. However, in most cases, we only need to obtain some records. In this way, how can we design a query? Of course, it will be a little more time-consuming. Besides, this article does not want you to use the recordset.

For example, if you only want to retrieve the p_name record, and the names of these records must start with a letter W, you need to use the following where clause:

SQL = "select p_name from products where p_name like 'W % '"

The where keyword is followed by the conditions used to filter data. With the help of these conditions, only data that meets certain criteria can be queried. In the preceding example, only the p_name record with the name of W is obtained.

In the preceding example, the percent sign (%) indicates that the query returns all records with W letters headers and any data or even no data. Therefore, when executing the preceding query, west and Willow will be selected from the products table and stored in the query.

As you can see, by carefully designing select statements, you can limit the amount of information returned in recordset.

These are just the first steps to grasp the use of SQL. To help you gradually understand the usage of complex select statements, let's take a look at the key standard terms: Comparison operators, these things are often used when you build your own select string to obtain specific data.

Where clause Basics

When creating a where clause, the simplest method is to use standard comparison symbols, which are <, <=,>, >=, <>, and =. Obviously, you will soon be able to understand the meaning and specific running results of the following code:

Select * from products where p_price> = 199.95

Select * from products where p_price <> 19.95

Select * from products where p_version = '4'

Note: here you will notice that the number 4 in the last example is enclosed in single quotes. The reason is that '4' in this example is the text type rather than the number type. Because you will put the SELECT statement in quotation marks and assign it to the variable as a value, you can also use quotation marks in the statement.

Comparison Operators

The comparison operator specifies the content range of the data retrieved from the table. You can use them to create filters to narrow the scope of the recordset, so that they only store the information you are concerned about under a given task.

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.