Re: Sorting column headings
Carmen --
You can hard-code " DESC " to your SQLStatement, or make it variable like
your Querystring("Order"):
SQLStatement = "Select * From calls Order by callID DESC"
SQLStatement = "SELECT * FROM calls ORDER BY " &
Request.QueryString("Order") & ", callID DESC"
You can also sort different columns ASC (ascending) or DESC (descending),
for instance:
SELECT callID, customerName FROM calls ORDER BY callID DESC, customerName
ASC
would give you the calls in newer to older order, but then sort them by the
customer name column.
Do be careful, however, when using ORDER BY and make sure you avoid using
column collections that don't have a corresponding or covering index if the
dataset being sorted is large, or you're likely to impair performance (and
possibly elicit the wrath of your DBA).
Alan
=====
"carmen" <carmen@iyahoo_Spam.com> wrote in message
news:uazrLZtbEHA.3012@tk2msftngp13.phx.gbl...[color=blue]
> I'm using the code below to display the results in rows with the column
> header as hyperlinks that will sort the rows by colum heading. Is there a
> way to have the results sorted (as default) in reverse order so that the
> most recent are at the top of the page also when the user selects the Open
> Date or Status column headings, sort the data in reverse order .
> Code is below.
> Thanks
>
> <%
> ppl_ctr=0
> dim mthd
> ' Set up SELECT Statement (Order by if user selected)
> If IsEmpty(Request.QueryString("Order")) Then
> SQLStatement = "Select * From calls Order by callID"
> strORDER = "Ordered by ID"
> Else
> SQLStatement = "SELECT * FROM calls ORDER BY " &
> Request.QueryString("Order") & ", callID"
> If (Request.QueryString("Order") = "callID") Then
> strORDER = "Ordered by ID"
> Else
> strORDER = "Ordered by " & Request.QueryString("Order")
> End If
> End If
> %>[/color]
[snip] |