cursor row count

  • I'm having trouble determining the number of rows in a cursor. Here is a snippet of code:

    DECLARE curPT CURSOR FAST_FORWARD FOR SELECT * FROM PT WHERE cGID = '1234567890'

    OPEN curPT

    PRINT @@ROWCOUNT

    This always prints 0. I know that 2 records exist in table PT.

  • @@ROWCOUNT returns the number of rows impacted by the last statement, which in this case is the OPEN. The OPEN didn't impact any results, and that is why you got a zero.

    What you need is a STATIC cursor and @@CURSOR_ROWS

    Good Luck!

    Chad

  • Thanks Chad - That worked great!

  • [font="Verdana"]

    Chad Crawford (1/30/2008)


    @@ROWCOUNT returns the number of rows impacted by the last statement, which in this case is the OPEN. The OPEN didn't impact any results, and that is why you got a zero.

    What you need is a STATIC cursor and @@CURSOR_ROWS

    Good Luck!

    Chad

    [/font]

    [font="Verdana"]Hi,

    But do u can elaborate its performance degradation? You may know already, and ppl suggests another to this as [highlight]Count()[/highlight] function, but i am unable to fix it up in code.

    But again Count() is also controversial. Any good/excellent alternative!

    Another one was of [highlight]INSENSITIVE[/highlight] .... . but what's its results on performance... !!!

    Thank you.[/font]

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

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