将一个字段转换成一个字符串的语句
例如数据 列Name
name
a
b
c
d
最后的结果
a*b*c*d*
www.2cto.com
declare @test table( name varchar(10))
insert into @test values ('a'),('b'),('c'),('d');
select distinct
(select cast(name as varchar(2))+'*' from @test for xml path('') ) as name from @test
www.2cto.com
输出结果:
(4 row(s) affected)
name
--------------------------------------------------
a*b*c*d*
(1 row(s) affected)