Geeks With Blogs
Doug.Instance Improving the world one post at a time

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






            select original_item + ','  

            from TABLE

            where condition_field = 'value'

            for xml path ('')  

        )   as varchar(max)

     ) as item

) as temp

Posted on Wednesday, February 9, 2011 1:06 PM SQL | Back to top

Comments on this post: Sub-Select to Delimited List in T-SQL

# re: Sub-Select to Delimited List in T-SQL
Requesting Gravatar...
How do I do this exact query with my select data being a decimal (14,4) they are dollar amounts. It comes back with msg 8114 Error converting data type varchar to numeric. I am not sure how to alter this to make it work.
Left by unsure on May 26, 2014 10:30 AM

Your comment:
 (will show your gravatar)

Copyright © Doug Lampe | Powered by: