Solved

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

Posted on 2009-05-14
3
160 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 5

Expert Comment

by:Aanvik
ID: 24385763
0
 
LVL 41

Accepted Solution

by:
ralmada earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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