Using SQL statements in ASP 10: View

Source: Internet
Author: User
View | Statement If there are many records on the page, in many cases, it is more efficient to sort the information alphabetically in descending order than the traditional ascending sort display. With your familiar ORDER BY clause, you can easily add this feature to the page, allowing users to control the views that their records display.

Suppose you have a page whose name is customers.asp, page execution selects all records from the Customers table and sorts the customer's last name in alphabetical order. Previously we have seen the sorted code, in order to achieve reverse ordering, you only need to add desc after an order BY expression:
SQL = "Select C_lastname, C_firstname, c_email from Customers order by C_lastnamedesc"

It's not bad to be in static mode. However, you may want to modify the above code to provide new GUI functionality:
<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 first link in the above code allows the user to modify the view of the page. You can overload the same page to view this information, but in the case of the Sort Descending link, the page assigns a value to the sort variable. Then, within the SQL statement, you do not specify DESC but instead take the value of the sort variable.

The next thing to do is to read the value of the sort at the top of the page.
<%
Sort = Request.QueryString ("sort")
%>

The code above checks out the available values for sort from the URL.

Doesn't make you too much effort, you can also adjust the same page allows users to sort specific columns. A simple Select Menu form control listing the sort by option can 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.