您的位置:首页 > 数据库

SQL Server把某个字段的数据用一条语句转换成字符串

2018-10-12 14:10 435 查看

例如数据 列Name


name
a
b
c
d

最后的结果

a*b*c*d*

declare @test table( namevarchar(10))
 insert into @testvalues('a'),('b'),('c'),('d');
                            
 select distinct
(select cast(name asvarchar(2))+'*'from @test for xml path(''))as name from @test


输出结果:

 (4 row(s) affected)
name
--------------------------------------------------
a*b*c*d*
(1 row(s) affected)

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐