SELECT statement
There are so many different SQL products that you may have to do before you throw away your sleeves. But you can get dizzy if you want to use both ASP and SQL at the same time. MySQL, SQL Server, and msql are excellent SQL tools, but unfortunately you don't need them to create a useful SQL statement in an ASP environment. However, you can take advantage of your knowledge of access and the corresponding access skills, plus our tips and tricks, and believe that you will be able to successfully add SQL to your ASP pages.
In the SQL world, the most fundamental operation is the SELECT statement. Many people will be familiar with the following when using SQL directly under Database Tools:
SELECT what
From whichtable
WHERE criteria
Executing the above statement creates a query that holds its results.
In the ASP page file, you can also use the above general syntax, but the situation is slightly different, ASP programming, the contents of the SELECT statement to be assigned as a string to a variable:
SQL = "Select what from whichtable WHERE criteria"
OK, understand the ASP under the SQL "speak" way, then follow the same pattern, as long as you meet your needs, the traditional SQL query mode and conditional query can be useful.
For example, suppose you have a data table in your database, the name is products, and now you want to take out all the records in the list. Then you write the following code:
SQL = "SELECT * FROM Products"
The function of the above code--SQL statement is to take out all the data in the table--after execution, all the records in the datasheet will be selected. However, if you only want to remove a specific column from the table, such as P_name. Then you can't use the * wildcard character, you have to type the name of a specific column, the code is as follows:
SQL = "Select P_name from Products"
After executing the above query, the contents of the Products table and the P_name column will be all selected.
Setting query conditions with a WHERE clause
Sometimes taking out all of the database records may be exactly what you want, but in most cases we usually just have to get some records. So how do you design the query? Of course it will be a bit more brain, and this article also deliberately do not want to let you use that what them recordset.
For example, if you're only going to take out P_name records, and the names of those records must start with the letter W, you'll need to use the following WHERE clause:
SQL = "Select P_name from the products WHERE p_name like ' w% '"
Where keywords are followed by the conditions used to filter the data, and with the help of these conditions, only data that satisfies a certain standard will be queried. In the above example, the result of the query will only get the P_name record with the first name in W.
In the example above, the percent sign (%) means that the query returns a record entry that starts with all the W letters and is followed by any data or even no data. Therefore, in the execution of the above query, West and Willow will be selected from the Products table and stored in the query.
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