摘要:[MSSQL] 透過FOR XML PATH('')實踐CONCATENATE
R1是summarize後的結果, R2是原始的raw data, 透過FOR XML PATH('')可實踐CONCATENATE, 網路上建議搭配STUFF, 個人覺得不需要
SELECT * FROM R1
SELECT * FROM R2
SELECT R1.*, SERNUM=(SELECT ', ' + SERNUM
FROM R2 R2
WHERE R1.INVNUM = R2.INVNUM FOR XML PATH(''))
FROM R1 R1