Sorting Recordsets

Results 1 to 4 of 4

Thread: Sorting Recordsets

  1. #1
    Join Date
    Dec 1969
    Posts
    24

    Default Sorting Recordsets

    Hi there,<BR><BR>I am trying to sort a recordset I have created.<BR><BR>Basically, what I want to do is simple. Sort the recordset by the Autonumbered key value (which is labelled ID). All I want to do is flip this around, so that instead of going 1,2,3... it goes 50,49,48 (so that most recent additions to the DB are shown first).<BR><BR>How do I sort my recordset to do this?<BR><BR>Info:<BR><BR>Fieldname: ID<BR>Recordset: objRecordset<BR>Table Name: Data<BR><BR>Thanks a ton!<BR><BR>Hank

  2. #2
    Ian Stallings Guest

    Default RE: Sorting Recordsets

    In the select statement you would use<BR>SELECT * ORDER BY ID DESC <BR><BR>This works on SQL server. Im not sure about Access to<BR>be honest, but it&#039s worth a try. To reverse it<BR>you would put ASC instead of DESC<BR><BR>hope this helps

  3. #3
    Join Date
    Dec 1969
    Posts
    128

    Default RE: Sorting Recordsets

    We use access and that sounds ok to me. What I usually do is cheat by using the access query builder thingy, and getting the query how I like it. Then I switch to SQL view and cut and paste the SQL into my ASP code, then I break it up into several lines and put in variables instead of hard coded values, as needed.

  4. #4
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Sorting Recordsets

    Mary, you cheater! :):)<BR><BR>Tee hee, whatever&#039s easier, eh? :)<BR><BR>Ian is right, ORDER BY works in Access. You can have it arrange it on auxillary columns as well. For example, if you do:<BR><BR>SELECT * FROM Users ORDER BY LastName<BR><BR>when two users have the same lastname they will be listed in some unknown order. Say you want it to be ordered by firstname, if the lastname is the same. You would do:<BR><BR>SELECT * FROM Users ORDER BY LastName, FirstName<BR><BR>I think you can have up to 16 comma-delimited column names, although I&#039d have to check SQL Books Online to make sure exactly.<BR>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •