Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Posts
    9

    Unanswered: Cursor Fetch Problem

    I'm using a cursor to get a rowset and then update that rowset with certain new values. So I have a basic while loop to check until @@fetch_status is not zero. However, this means that it tries to fetch one time a row that does not exist before it exists the loop. This gives out an error message that the query had an error in it. I know it's not an error, but is there any way way to avoid that? Is there a way to peek ahead to see if I'm currently fetching the last row and exit before trying to fetch another one? Maybe there is a way to see how many rows were returned when the cursor was opened? This is a dynamic cursor so @@CURSOR_ROWS won't work as far as I know.

    Thank you.

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    What was the exact error?
    For more information on cursors refer to books online.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  3. #3
    Join Date
    Jan 2003
    Location
    Nottinghamshire, UK
    Posts
    364
    How about using the dreaded GOTO
    Code:
    WHILE 1 = 1
    
    BEGIN
        
       FETCH NEXT..................
    
        IF  (@@FETCH_STATUS <> 0) GOTO CloseCursor
    
        .......update rowset.........
    
    END
    
    CloseCursor:
    
    CLOSE ...........
    DEALLOCATE .............
    GW
    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

Posting Permissions

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