存储过程 游标
过程片段:
declare master_cursor CURSOR FOR
select hangbiaoshi from tab_Test order by hangbiaoshi desc
open master_cursor
FETCH NEXT FROM master_cursor into @hangbiaoshi
while @@fetch_status = 0
BEGIN
set @tmpcontent = ''
declare senc_cursor CURSOR FOR
select userName,content,date from tab_information where guanlianbiaoshi = @hangbiaoshi
open senc_cursor
FETCH NEXT FROM senc_cursor into @user,@content,@date
while @@fetch_status = 0
begin
set @tmpcontent = @tmpcontent + @user + ':' + @content + '(' + convert(varchar(50),@date,120) + ')' + '<br>'
FETCH NEXT FROM senc_cursor into @user,@content,@date
end
insert into #resultTable values (@hangbiaoshi,@tmpcontent)
CLOSE senc_cursor
DEALLOCATE senc_cursor
FETCH NEXT FROM master_cursor into @hangbiaoshi
END
CLOSE master_cursor
DEALLOCATE master_cursor
select * from #resultTable