日期:2014-05-18  浏览次数:20415 次

求解游标问题,在线急等!
首先我已经写好了一个p_auto_store_bak的存储过程,该存储过程有6个参数,该6个参数的取值来自于表u_batsale_c_bak,此表中有1000条记录,求解怎么通过游标实现自动从表u_batsale_c_bak中的每条记录里取6个对应值赋给存储过程的6个参数,从而执行存储过程??或者还有别的其它方法吗???

------解决方案--------------------
SQL code

    declare cursor1 cursor for   
    select col1,col2,col3,col4,col5,col6
    from u_batsale_c_bak --order by ...
    
    open cursor1  
    fetch next from cursor_now into @col1,@col2,@col3,@col4,@col5,@col6
    while @@fetch_status = 0
    begin
        exec p_auto_store_bak @col1,@col2,@col3,@col4,@col5,@col6
        fetch next from cursor_now into @col1,@col2,@col3,@col4,@col5,@col6
    end
    
    close cursor1
    deallocate cursor1

------解决方案--------------------
还能想到的就是去拼接动态执行的SQL字符串。