Results 1 to 7 of 7

Thread: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    How can I get exactly row 6 or whatever, row 234 from simple SELECT statement in Access 2000 SQL?

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,422

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    You don't, since access doesn't have a ROW_NUMBER-Function.
    See your other thread.
    I've told you there is a workaround using DCOUNT

    EDIT: There is a second workaround i just thought of:
    You could use the TOP n -function, and then retrieve the last recordset, but obviously, this would only work on sorted queries (ORDER BY-clause)

    rs.open "SELECT TOP 6 ID, clientname FROM myclient ORDER BY Turnover",blahblah
    rs.movelast
    Last edited by Zvoni; Jul 3rd, 2018 at 08:24 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    If you are using vba code. Open the recordset, and put a while loop in to move to next recordset until the number is reached or there are no more records.
    If I remember correctly there was a method to jump straight to a specific x row method. found it!
    Don't usually use it but perhaps this is what you were loking for (Note its DAO)

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    in ADO the move method should do what you want, move # records from bookmark adbookmarkfirst
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,422

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    It doesn't matter which "workaround" he uses, in the worst case it's going to be a performance-issue.
    He'll always have to retrieve the full Query (a few thousand records?), and then in a second step move to the desired record.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    He'll always have to retrieve the full Query
    bad table design?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,422

    Re: How to get exactly row 6 from a SELECT result in Access 2000 SQL?

    Quote Originally Posted by westconn1 View Post
    bad table design?
    No idea.
    But if it's a table with a lot of columns, it might be an idea to split it up into a master-table with just the columns you need for the Query, with a Detail-Table in 1:1 relation.
    Meaning: Do the query on the stripped-down master-table, move cursor to desired position, read the ID/PK from that record, retrieve the remaining informations from the detail-table.

    But without knowing his setup.... *shrug*

    EDIT: If he knows which record (ROW_NUMBER) he needs before firing the query, i think my approach with "SELECT TOP n ....." and then Record.MoveLast would still be his best bet.
    Of course, i know that the further in the back the record is he seeks, the more records he has to load.
    With TOP n he can at least cut off everything after it
    Last edited by Zvoni; Jul 4th, 2018 at 06:21 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width