Limiting the number of rows returned from a cursor

  • I am working in SQL Server 2000.

    For testing purposes, how can I limit the number of rows returned from a cursor?

  • Could you SELECT TOP ... when creating your cursor?

  • Many thanks for suggesting the SELECT TOP ... option

    It worked perfectly!

  • Hi,

    Certainly you can restrict the no. of records using TOP, but this is performnace issue. It would be better to use to some WHERE condition to restrict the records.

    Thanks -- Vj

    http://dotnetvj.blogspot.com

  • trigonom (2/13/2008)


    I am working in SQL Server 2000.

    For testing purposes, how can I limit the number of rows returned from a cursor?

    You didn't answer the question that came up right after your post... why do you think you need to use a cursor? What is it that you're trying to do? Lot's of good ways to avoid the slowness and overhead of a cursor...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply