当前位置: 移动技术网 > IT编程>数据库>MSSQL > 分组将列值转换为以逗号分隔字符串

分组将列值转换为以逗号分隔字符串

2019年05月12日  | 移动技术网IT编程  | 我要评论

牡丹鹦鹉吃什么,吴艳樱,ca1327航班

实现这篇之前,可以先参考这篇《数据表列值转换为逗号分隔字符串

上这篇,只是输出一个值,现我们把数据表进行分组。

先把上一篇的源始数据再组织一下:

 

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

 

接下来,再修改一下那个存储过程:

 

举例说明:

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网