网络编程
位置:首页>> 网络编程>> 数据库>> SQL Server把某个字段的数据用一条语句转换成字符串

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

作者:junjie  发布时间:2024-01-13 16:10:12 

标签:SQL,Server,字段,数据,转换,字符串

例如数据 列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)

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com