提示错误:
======================================================
服务器: 消息 16916,级别 16,状态 1,过程 test,行 99
名为 'm_curTemp' 的游标不存在。
服务器: 消息 16916,级别 16,状态 1,过程 test,行 100
名为 'm_curTemp' 的游标不存在。
服务器: 消息 16916,级别 16,状态 1,过程 test,行 106
名为 'm_curTemp' 的游标不存在。
服务器: 消息 16916,级别 16,状态 1,过程 test,行 107
名为 'm_curTemp' 的游标不存在。

解决方案 »

  1.   

    set @str = 'declare m_curTemp Scroll cursor for ' + @str +
    ' open m_curTemp'
    +' fetch absolute @m_intStartRecord from m_curTemp'
    +' while  @@fetch_status = 0'
    +' fetch next from m_curTemp'
    +' --关闭指针'
    +' close m_curTemp'
    +' deallocate m_curTemp'
    exec(@str)
    set rowcount 0
      

  2.   

    DECLARE cursor_name [ INSENSITIVE ] [ SCROLL ] CURSOR 
    FOR select_statement 
    [ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } ]标准的SQL-92语法如上
    必须有for select_statement语句只定一个CURSOR,不指定它所对应的记录集是不行的
      

  3.   

    set @str = 'declare m_curTemp Scroll cursor for ' + @str +
    ' open m_curTemp'
    +' fetch absolute '+cast(@m_intStartRecord as varchar(10))+' from m_curTemp'
    +' while  @@fetch_status = 0'
    +' fetch next from m_curTemp'
    +' --关闭指针'
    +' close m_curTemp'
    +' deallocate m_curTemp'
    exec(@str)
    set rowcount 0
      

  4.   

    你想动态生成CURSOR,不过这样子是不行的
    我看你的几个脚本返回的结果集的字段都是相同的,我想最好建一个临时表temptable,然后定义cursor for select * from temptable
    再将数据insert到temptable中
    再open cursor没试过,感觉是一可行之路
      

  5.   

    要不就象我爱燕子说的那样将处理CURSOR的部分也用动态SQL来做吧
    不知道哪个效率好
      

  6.   

    其他就是把你的查询改成直接执行的!
    select * from ...这种,
    而不是
    @str='select * from ...'
    exec(@str)