SELECT
[vendorId],
STUFF((
SELECT ', ' + [Name]
FROM #YourTable
WHERE (ID = Results.ID)
FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)')
,1,2,'') AS nameAll
FROM #YourTable Results
GROUP BY [vendorId]
SELECT DISTINCT CT2.vendorId, substring
((SELECT ',' + CT1.name AS [text()]
FROM dbo.vendorContact AS CT1
WHERE CT1.vendorId = CT2.vendorId
ORDER BY CT1.vendorId
FOR XML PATH(''), TYPE ).value('(./text())[1]', 'NVARCHAR(MAX)'), 2, 1000) AS [nameAll]
FROM dbo.vendorContact CT2
แต่ sql server จะฟ้อง error เวลาเข้าไป design แต่เวลา run ก็ผ่าน ไม่ error อะไร