我用select 语句得到一张表是
ID beizhuxin States Company_unti
1 A 0 1#
2 A 0 2#
3 B 0 1#
除了states是int,其它都是varchar(10),在不改变数据库结构的情况下,实现
ID beizhuxin Company_Unti
1 A 1#,2#
2 B 1#
------解决方案--------------------
select beizhuxin,
[ values ] = stuff (( select ' , ' + [ Company_unti] from tb t where beizhuxin = tb.beizhuxin for xml path( '' )), 1 , 1 , '' )
from tb
group by beizhuxin