Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2002
    Posts
    8

    Unanswered: Selecting a particular row....

    Hi,

    how do I select only second row or 4-10 rows in the select statement
    not using Cursor and fetch statements ??


    thanx in advance
    cheers!
    Kiran

  2. #2
    Join Date
    Feb 2002
    Location
    Buffalo, NY
    Posts
    9
    Use the TOP keyword in the statement with the number (or percentage) of records you want.

    example:

    select TOP 2 * from sysobjects

  3. #3
    Join Date
    Feb 2002
    Posts
    8
    Hello,

    thanx for the reply.

    Actually this won't work if I need to retirieve only the 2nd row of a ceratin resultset or even a resultset of Row No 4 to Row No 10


    cheers!
    Kiran

  4. #4
    Join Date
    Feb 2002
    Location
    Buffalo, NY
    Posts
    9
    Then you have to get fancy -

    select top 6 * from sysobjects where name not in (select top 4 name from sysobjects order by name) order by name

    will return #s 4 - 10

    select top 1 * from sysobjects where name not in (select top 1 name from sysobjects order by name) order by name

    will return the 2nd row

    I have had to use this quite a bit and once you figure it out, it is handy.

    Hope this helps
    Last edited by freeloader; 03-05-02 at 09:36.

  5. #5
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    See past posting:

    sql query help 12-14-2001

Posting Permissions

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