一条话语将一个字段数据换转成一个字符串

一条语句将一个字段数据换转成一个字符串例如数据 列Namename abcd最后的结果a*b*c*d*declare @test table

一条语句将一个字段数据换转成一个字符串

例如数据 列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 namefrom @test

 

输出结果:

 (4 row(s) affected)

name

--------------------------------------------------

a*b*c*d*

(1 row(s) affected)

 

3楼han_yankun2009昨天 14:55
不错额
2楼leihengxin昨天 08:29
嗯。
1楼liutengteng130昨天 08:01
学习了,加油。