Solved

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

Posted on 2009-05-14
3
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ISDATE() not working properly on my table? Any suggestions. 7 51
tempdb log keep growing 7 56
Update one rows based on previous row 5 35
SQL- GROUP BY 4 51
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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