Results 1 to 10 of 10

Thread: DB Question just asking

  1. #1

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    DB Question just asking

    is it possible to select the 5th record until the 30th record in a sql query?





    =============
    ..code masters..

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: DB Question just asking

    Not sure if there is a shortcut.

    I would load the query into a datatable and iterate through the datatable as follows:

    VB Code:
    1. Dim str As String
    2. Dim myDataTable As New DataTable
    3.  
    4. 'Populate your datatable with all rows
    5.  
    6. For i = 4 to 29 'row numbers 5 to 30
    7.    'assign the value of the first field in row i to str
    8.    str  = myDataTable.Rows(i).Item(0)            
    9. Next

  3. #3

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: DB Question just asking

    i know that, i am just asking on the sql part if it is possible?





    =============
    ..code masters..

  4. #4
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    263

    Re: DB Question just asking

    Check out the top method not sure if you can amend that?

  5. #5

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: DB Question just asking

    SELECT *
    FROM (Select top 30 * from Products) where productID > 4;





    =============
    ..code masters..

  6. #6
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    263

    Re: DB Question just asking

    Did it work??

  7. #7

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: DB Question just asking

    it did work. Try it on your Northwind database. it will work:-0





    =============
    ..code masters..

  8. #8
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    263

    Re: DB Question just asking

    Glad i could help!

  9. #9
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: DB Question just asking

    Quote Originally Posted by iehjsucker
    SELECT *
    FROM (Select top 30 * from Products) where productID > 4;
    It will work provided that a product with ProductID between 1 and 4 (inclusive) has not been deleted. If this is the case, then ProductID 5 can at most be the fourth record and should be excluded but will not be excluded according to the WHERE clause above.

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: DB Question just asking

    You could populate a datatable with "Select top 30 * from Products" then:
    VB Code:
    1. For i = 0 to 3
    2. myDataTable.Rows.RemoveAt(i)
    3. Next
    to remove the first 4 rows.

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