Multiple rows into a single row and combine column SQL

前端 未结 1 1492
清酒与你
清酒与你 2020-12-11 17:20

I am trying to make this view query two tables and then roll up each Program ID into one row with all the AttributeNames in the AttributeNames colum together

I joine

相关标签:
1条回答
  • 2020-12-11 18:12
    select ProgramId,
    stuff(
    (
        select ','+ [attributename]
        from Table1 
        where programid = t.programid for XML path('')
    
    ),1,1,'') as AttributeNames
    from (select distinct programid 
          from Table1 )t
    

    Check out my sql fiddle

    Results

    PROGRAMID   ATTRIBUTENAMES
    887         Study Design,Control Groups,Primary Outcomes
    
    0 讨论(0)
提交回复
热议问题