ID card - Debt Consolidation - William Hill Vouchers - Florida Property - Debt Consolidation

PDA

View Full Version : ASP Question: ORDER BY a column?


gilgalbiblewheel
Mar 29th 2005, 10:26 am
If I have several fields:
a | b | c | d | e

and the original SQL = SQL & " ORDER BY a ASC ".

I want to place links to b, c, d, e to make the table of results to show by ascending order of b (or , c, d, e).

do I need to place an "if/ end if" in the sql or do I put some statement in the paging?

example
a (ORDER BY a ASC)| b | c | d | e
1 | 3 | z
2 | 2 | y
3 | 1 | x
4 | 5 | w
5 | 4 | v

to

a | b (ORDER BY b ASC)| c | d | e
3 | 1 | x
2 | 2 | y
1 | 3 | z
5 | 4 | v
4 | 5 | w

iShopHQ
Mar 29th 2005, 11:40 am
Use a querystring

dim vOrderBy, strSQL

vOrderBy = ""
vOrderBy = request.querystring("ob")

strSQL = ""
strSQL = "SELECT * from tab_Whatever ORDER BY "&vOrderBy&" "

Your links would be <a href="link.asp?ob=a">Link</a>

Or you could even put little Up/Down arrows at the top of each column and then pass an ASC or DESC

Dim vOrderBy, vOrder, strSQL

vOrderBy = ""
vOrder = ""
strSQL = ""

vOrderBy = ""
vOrderBy = request.querystring("ob")

vOrder = ""
vOrder = request.querystring("o")

Select case vOrder
Case "a"
vOrder="ASC"
Case "d"
vOrder="DESC"
End Select

strSQL = ""
strSQL = "SELECT * from tab_Whatever ORDER BY "&vOrderBy&" "&vOrder&" "

Your links would be
Column A <a href="link.asp?ob=a&o=a">Up Arrow</a> : <a href="link.asp?ob=a&o=d">Down Arrow</a>