将数据表的某一列值,转换为逗号分隔字符串:
先准备一些数据:
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