-3

I'm a litte confused with query, I have problem to showing table in query from SQL Server. Hope my screenshot below clearly shows my problem:

this is my expectation

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1
    ;WITH tb(id,id_ang,bulan)AS(
       SELECT 1,1,1 UNION
       SELECT 2,2,1 UNION
       SELECT 3,1,13 UNION
       SELECT 4,1,2
    )
    SELECT id_ang,STUFF(c.bulans,1,1,'') AS bulans FROM tb 
    OUTER APPLY(SELECT ','+LTRIM(bulan) FROM tb AS tt WHERE tt.id_ang=tb.id_ang ORDER BY ID FOR XML PATH('') ) c(bulans)
    GROUP BY id_ang,c.bulans
id_ang  bulans
1   1,13,2
2   1
Nolan Shang
  • 2,312
  • 1
  • 14
  • 10