Best practice for testing @@FETCH_STATUS for a cursor

  • BOL (2005) gives cursor examples which test @@FETCH_STATUS in different ways.  I wondered if there is any difference/best practice.

    The 3 examples are:

    WHILE (@@FETCH_STATUS <> -1)

    BEGIN

       IF (@@FETCH_STATUS <> -2)

    WHILE @@FETCH_STATUS = 0

    WHILE (@@FETCH_STATUS <> -1)

    Thanks,

    Barry

  • I only needed WHILE @@FETCH_STATUS = 0

    Checking for other conditions would complicate my code.

    *

    0FETCH statement was successful.
    -1FETCH statement failed or the row was beyond the result set.
    -2Row fetched is missing.

Viewing 2 posts - 1 through 1 (of 1 total)

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