SQL Server把某个字段的数据用一条语句转换成字符串
2022-11-12 09:39:22
内容摘要
这篇文章主要为大家详细介绍了SQL Server把某个字段的数据用一条语句转换成字符串,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
例如数
文章正文
这篇文章主要为大家详细介绍了SQL Server把某个字段的数据用一条语句转换成字符串,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
例如数据 列Name
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 | <code> name a b c d </code> |
代码如下:
1 2 | <code> a*b*c*d*</code> |
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
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 | <code> (4 row(s) affected) name -------------------------------------------------- a*b*c*d* (1 row(s) affected) </code> |
注:关于SQL Server把某个字段的数据用一条语句转换成字符串的内容就先介绍到这里,更多相关文章的可以留意
代码注释