一对多合并记录

来源:互联网 发布:阿里云推荐码有什么用 编辑:程序博客网 时间:2024/05/10 03:20
   select  field1,field2,stuff(
           (select ', '+rtrim(gr.GuessRate)
         from table2 as gr
         where a.bsid=gr.bsid and a.ByID=gr.ByID
         for xml path(''), type).value('text()[1]', 'nvarchar(max)'), 1, 2, '') as  Grate