Declaring Cursors error

  • With the line of code:

    DECLARE MyCursor CURSOR SCROLL DYNAMIC FOR

    SELECT....

    I'm getting a error message: the variable MyCursor does not currently have a cursor allocated to it.

    Can anyone help?

    DavidFC

  • SQL Server raises this error if a referenced cursor variable exists but does not have a cursor currently allocated to it - have seen this if you are opening the cursor before trying to fetch - is this your case?

    Paul Ibison

    Paul.Ibison@btinternet.com


    Paul Ibison
    Paul.Ibison@replicationanswers.com

  • Paul, Yes I am, i.e.

    OPEN MyCursor

    FETCH NEXT FROM MyCursor INTO @warehouse.

    Do I need to swop these lines around

    DavidFC

  • Sorry David, I copied and pasted my comments incorrectly - should have said "if you are not opening the cursor before ...". As long as there are no 'Close MyCursor' commands inbetween the open and fetch, your code looks ok and I'm stuck.

    Paul Ibison

    Paul.Ibison@btinternet.com


    Paul Ibison
    Paul.Ibison@replicationanswers.com

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

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