CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2001
    Posts
    60

    Selecting X records

    Hello,

    I have a database with auto index as the key.
    Its' max size is 50000 records.
    I want to get the first 10000 records and than the second 10000 records and so on.

    How do I do that?
    I can't ask from index X to index Y because I don't know X and Y that will give me exactly 10000 records.
    I can get all indexes of the table to an arrray and find the index that is in the 10000 spot in the array.

    Is there an other way?

  2. #2
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309
    As long as there is an column with a consective autonumber you are using you can do

    Option 1

    SELECT * FROM
    {
    SELECT TOP 10000 * FROM
    {
    SELECT TOP n * FROM tblX ORDER BY ColAutoNum
    } AS IQ
    ORDER BY ColAutoNum DESC
    } AS OQ
    ORDER BY ColAutoNum

    Where n represents the highest position to return.

    Option 2

    SELECT * FROM tblX OQ WHERE (SELECT (COUNT(*) + 1) AS CNT FROM tblX IQ WHERE IQ>ColAutoNum < OQ.ColAutoNum) BETWEEN n1 AND n2

    where n1 is the starting position and n 2 is the ending.

  3. #3
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249
    Another means is by utilizing the CacheSize of the recordset ...

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

Featured