Use SQL statement 10 in ASP: View

Source: Internet
Author: User
If there are many records on the page, in many cases, sorting the information in alphabetical descending order is more efficient than the traditional ascending order display. Using the order by clause you are familiar with, you can easily add this function on the page, allowing users to control the view of their records.
Assume that you have a page named MERS. asp. The page execution selects all records from the customers table and sorts the customer surnames alphabetically. We have seen the sorting code before. To achieve reverse sorting, you only need to add desc after the order by expression:
SQL = "SELECT c_lastname, c_firstname, c_email FROM Customers ORDER BY c_lastnamedesc"
It does not depend on static mode. However, you may want to modify the above code to provide new GUI functions:
<A href = "customers. asp"> Sort Ascending </A> | <a href = "customers. asp? Sort = desc "> Sort Descending </A>
<P>
<%
SQL = "SELECT c_lastname, c_firstname, c_email FROM Customers ORDER BY c_lastname" & sort &""
Set objRec = objConn. Execute (SQL)
While Not objRec. EOF
Response. WriteobjRec ("c_lastname") & "," & objRec ("c_firstname ")&"
"& ObjRec (" c_email ") &" <P>"
ObjRec. MoveNext
Wend
%>
The link starting with the above code allows users to modify the view of the page. You can reload the same page to view this information. However, when the Sort Descending link is used, the page will assign a value to the sort variable. Then, the value of the sort variable is used instead of the desc variable specified in the SQL statement.
The following is how to read the sort value at the top of the page.
<%
Sort = Request. Querystring ("sort ")
%>
The above code detects the available value of sort from the URL.
It does not take much effort. You can also adjust the order of specific columns on the same page. A simple SELECT menu form control listing the sort by option may be a more convenient measure.

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.