Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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

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
meteorelec
Asked:
meteorelec
1 Solution
 
cdaly33Commented:
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
 
ralmadaCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now