实现这篇之前,可以先参考这篇《数据表列值转换为逗号分隔字符串》
上这篇,只是输出一个值,现我们把数据表进行分组。
先把上一篇的源始数据再组织一下:
if object_id('tempdb..#temptable') is not null
begin
drop table #temptable
end
create table #temptable ([id] int not null,[type] nvarchar(20) null,[category] nvarchar(40) null)
insert into #temptable ([id],[type],[category]) values (1,'table','table'),
(2,'table','view'),
(3,'sp','store procedure'),
(4,'fun','table-valued function'),
(5,'fun','scalar-valued function'),
(6,'type','user-defined table type')
select [id],[type],[category] from #temptable
go
接下来,再修改一下那个存储过程:
举例说明: