Well, I often need to create a comma-separated list out of values in a table.
here I found this pretty ellegant sollution:
STUFF(
(
SELECT ', ' + Supplier_ID
FROM SomeTable
join SomeOtherTable
on Something
WHERE SomeCondition
FOR XML PATH('')), 1, 1, '') as AllSuppliers
(
SELECT ', ' + Supplier_ID
FROM SomeTable
join SomeOtherTable
on Something
WHERE SomeCondition
FOR XML PATH('')), 1, 1, '') as AllSuppliers
No comments:
Post a Comment