1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP Question: ORDER BY a column?

Discussion in 'C#' started by gilgalbiblewheel, Mar 29, 2005.

  1. #1
    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
     
    gilgalbiblewheel, Mar 29, 2005 IP
  2. iShopHQ

    iShopHQ Peon

    Messages:
    644
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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>
     
    iShopHQ, Mar 29, 2005 IP