Sort indicates one or more field names on which the Recordset is sorted, and whether each field is sorted in descending or ascending order.It is depending upon the need of report.
Settings and Return Values
Sets or returns a String value that indicates that is field names in the Recordset on which to sort. Every name is separated by a comma(,), and is optionally followed by a blank and the keyword, ASC, which sorts the field in ascending order, or DESC(descending order), which sorts the field in descending order. By default, if there is no keyword is specified, the field is sorted in ascending order.
For Example:Sort a records in ascending order.
Here an example is given that sort the record from recordset "data" by the ascending order of the Employee first name with their occupation.
Sort and display the records from a table on a fieldname ascending.
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/database/data.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT FirstName, LastName, Occupation FROM Employees ORDER BY FirstName"
rs.Open sql, conn
% >
<table border="1" width="100%">
<tr>
<%
for each x in rs.Fields
response.write("<th align='center' bgcolor='#9ABEF4'>"& x.name & " </th>")
next
%>
</tr>
<%
do until rs.EOF
%>
<tr>
<%for each x in rs.Fields%>
<td> <%Response.Write(x.value)%> </td>
<%
next
rs.MoveNext
%>
</tr>
<%
loop
rs.close
conn.close
%>
</table>
</body>
</html>
Output Display as:
FirstName
LastName
Occupation
Antony
Trig
Sys Admin
Brain
Doe
CEO
David
Rogers
Design
George
Stockton
CFO
Hilary
Evans
Secretary
Jack
Campbell
CFO
Jessica
Jones
Senior Developer
Jim
Sandler
CEO
John
Smith
Project Designer
Will
Johnson
Architech
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.