列值转换为逗号分隔字符串
程序员文章站
2022-06-17 08:56:50
将数据表的某一列值,转换为逗号分隔字符串: 先准备一些数据: DECLARE @t AS TABLE([Datas] NVARCHAR(40)) INSERT INTO @t ([Datas]) VALUES(N'DF'),(N'W4F'),(N'EYY'),(N'ER'),(N'GFF'),(N' ......
将数据表的某一列值,转换为逗号分隔字符串:
先准备一些数据:
declare @t as table([datas] nvarchar(40)) insert into @t ([datas]) values(n'df'),(n'w4f'),(n'eyy'),(n'er'),(n'gff'),(n'a445') select [datas] from @t order by [datas]
一二句sql代码的事:
declare @commadelimitedstring nvarchar(max) select @commadelimitedstring = isnull(@commadelimitedstring + ',', '') + [datas] from @t order by [datas] select @commadelimitedstring
上一篇: 课堂笔记1