表
A B
1 a
2 b
3 c
想把B字段全部查询出来,得到结果:a,b,c
以逗号分割。
A B
1 a
2 b
3 c
想把B字段全部查询出来,得到结果:a,b,c
以逗号分割。
-
SQL code
-
if not object_id('tb') is null drop table tb Go Create table tb([A] int,[B] nvarchar(1)) Insert tb select 1,N'a' union all select 2,N'b' union all select 3,N'c' Go Select distinct stuff((select ','+[B] from tb for xml path('')),1,1,'') from tb t /* a,b,c */