Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

put a colum of data and insert it into a single field with comma seperators

Posted on 2009-05-14
3
Medium Priority
?
168 Views
Last Modified: 2012-05-07
I have a table  called [table_a] and it has a column name [product],

when i run this statement  
'SELECT product FROM table_a'

it returns

product
A0023
GG990
HHG176
KKJ1212

what statement would i need to return one record in the below format

A0023,GG990,HHG176,KKJ1212

0
Comment
Question by:meteorelec
3 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24385748
I've used the method in this article many times with great results.
http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string
0
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 24385780
Please give this a try:
SELECT Product = REPLACE( 
	( 
	SELECT 
	Product AS [data()] 
	FROM 
	Table_a c 
	ORDER BY 
	c.Product 
	FOR XML PATH ('') 
	), ' ', ',')
 

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question