Sub-Select to Delimited List in T-SQL
- by Doug Lampe
The following transact-SQL statement can be used with Microsoft SQL Server to create a delimited list from a sub-query. In this case the delimiter is a comma.
SELECT Left(item,LEN(item)-1)as delimited_list
FROM (
select
CAST
(
(
select original_item + ','
from TABLE
where condition_field = 'value'
for xml path ('')
) as varchar(max)
) as item
) as temp