select (select title+'-' from table_b where pid=a.id for xml path('')) 
From table_a a如搜索出来后有重复的值(title1,title3重复)
title1-title1-title2-title3-title3-title4-title5怎么把重复的值合并,实现
title1-title2-title3-title4-title5

解决方案 »

  1.   

    select (select title+'-' from table_b where pid=a.id group by title
                                          for xml path(''))  
    From table_a a
      

  2.   


    select (select distinct title+'-' from table_b where pid=a.id for xml path(''))  
    From table_a a
      

  3.   


    select (select distinct title+'-' from table_b where pid=a.id for xml path(''))  
    From table_a a
    ++
      

  4.   

    select
     (select distinct title+'-' from table_b where pid=a.id for xml path(''))  
    From
     table_a a