declare @col1 varchar(10),@col2 int,@rs varchar(8000)
set @rs='<table>'
DECLARE authorcursor CURSOR FOR 
SELECT col1,col2 from ta 
open authorcursor
fetch next from authorcursor into @col1,@col2
while @@fetch_status=0
begin
set @rs=@rs+'<tr><td>'+@col1+'</td><td>'+cast(@col2 as varchar)+'</td></tr>'
fetch next from authorcursor into @col1,@col2
end
set @rs=@rs+'</table>'
close authorcursor
deallocate authorcursor

解决方案 »

  1.   

    create table #t(...)--这里定义与存储过程返回结果集结构相同的临时表
    insert #t exec sp_test--将存储过程返回结果集存储到临时表declare a cursor for
      select ... from #t--游标操作临时表
    ...
      

  2.   

    谢谢大家!
    我现在是这样的情况我已经做好了一个存储过程,有记录集返回.现在就是要使用现成的记录集.
    exec(sp_test) 就有返回的记录集,我想直接使用这个记录集是不是没有办法啊!
      

  3.   

    to: pbsql(风云) 
    你办法可以,谢谢!不过create table 一般要知道table的结构,如果不知道就不行了..我觉得类似下面就比较好一些
    select * into #temp from table1