select pro, city=stuff((select ','+city from @t where pro=t.pro for xml path('')), 1, 1, '') 
from @t t group by pro       province   citycode   cityname
       湖南         01        长沙
       广东         02        广州
       广东         03        深圳如何查询出
1       湖南   01      长沙
2       广东   02/03   广州/深圳 
 谢谢

解决方案 »

  1.   

    http://topic.csdn.net/u/20110429/09/eb781822-7975-4d76-90d3-2f8862b5e35f.html
    11楼
      

  2.   

    select pro,city=stuff((select '/'+citycode from @t where pro=t.pro for xml path('')), 1, 1, ''),
               cityname=stuff((select '/'+cityname from @t where pro=t.pro for xml path('')), 1, 1, '') 
    from @t t group by pro 
      

  3.   

    select
     pro,
     city=stuff((select '/'+citycode from @t where pro=t.pro for xml path('')), 1, 1, ''),
     cityname=stuff((select '/'+cityname from @t where pro=t.pro for xml path('')), 1, 1, '') 
    from
     @t t 
    group by
     pro