Declaring a cursor with a variable

  • I am having trouble with a cursor declaration. I am trying to declare the cursor with a variable for the tablename, but for some reason, it's not working. Here is the code I'm using:

    exec('DECLARE cSubList CURSOR local scroll FOR SELECT acct FROM ' +

    @listtbl + ' WHERE listnum = ' + @list)

    When I try to open the cursor, cSubList, I get the message: A cursor with the name 'cSubList' does not exist. Any ideas?

  • You are using the keyword 'local'

    quote:


    I am having trouble with a cursor declaration. I am trying to declare the cursor with a variable for the tablename, but for some reason, it's not working. Here is the code I'm using:

    exec('DECLARE cSubList CURSOR local scroll FOR SELECT acct FROM ' +

    @listtbl + ' WHERE listnum = ' + @list)

    When I try to open the cursor, cSubList, I get the message: A cursor with the name 'cSubList' does not exist. Any ideas?


  • Thanks! That worked!

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

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