@@FETCH_STATUS can be -2

  • Hi,

    In which case @@FETCH_STATUS can be -2. I know SQL Server online book tell when Row fetched is missing.

    I need more explanation please, because I have randomly @@FETCH_STATUS=-2 (it appears every 20 executions of the TSQL code).

    Ahmed

  • AFAIK, this usually happens when some process OUTSIDE of the cursor deletes a row in the table the cursor is based on.

    So - if job 1 opens a cursor and starts looping through records in table1, and while Job 1 is looping, Job 2 comes along and deletes certain records in table1, job 1 might return a -2 when it tries to retrieve a row it was expecting to find (because it was there when the cursor started).

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi Ten,

    Thanks for your reply

    I have just a couple of sp_executesql (just select statments), I don't use an update or an other cursor.

    Ahmed.

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

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