这个语句应该怎么修改下面的SQL语句? 目的是想使sp_columns存储过程返回的列作为游标
declare cursor1 cursor for  sp_columns table1

解决方案 »

  1.   

    declare cur cursor for select * from openrowset('sqloledb','trusted_connection=yes','master..sp_columns ''table1''')
    open cur
    fetch next from cur
    while @@fetch_status = 0
    begin
          ...      /*对结果集进行处理*/
          fetch next from cur
    end
    close cur
    deallocate cur
      

  2.   

    USE pubs
    GO
    DECLARE authors_cursor CURSOR FOR
    SELECT au_lname FROM authors
    WHERE au_lname LIKE "B%"
    ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch.
    FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
    WHILE @@FETCH_STATUS = 0
    BEGIN
       -- This is executed as long as the previous fetch succeeds.
       FETCH NEXT FROM authors_cursor
    ENDCLOSE authors_cursor
    DEALLOCATE authors_cursor
    GOau_lname                                 
    ---------------------------------------- 
    Bennet                                   
    au_lname                                 
    ---------------------------------------- 
    Blotchet-Halls                           
    au_lname                                 
    ----------------------------------------
      

  3.   

    游标的基本使用方法在SQL帮助文档里面写的很详细