alter proc tieview
[email protected] int
as
declare mycursor cursor for
select author,id from tie where biaoji=2
declare @aa varchar(50)
declare @bb int
open mycursor
fetch next from mycursor into @aa,@bb
while @@fetch_status=0
begin
select a.*,b.content from usermsg a,tie b where [email protected] and [email protected]
fetch next from mycursor into @aa,@bb
end
close mycursor
deallocate mycursor
这个得出好几个结果
我想把他们合并成一个结果集,我用UNION ALL,但写到游标循环里就出错.实在没法了..求教各位了
------解决方案--------------------
作过表变量,插进去就行了
------解决方案--------------------
也可以建全局临时表或建函数返回表集合(而非proc)
------解决方案--------------------
对应你的select a.*,b.content from usermsg a,tie b where [email protected] and [email protected]
定义一个临时表.
游标每执行一次.插入一条记录