Subject: Concatenate multiple records into one
Posted By: Raman Pahwa Post Date: 8/18/2008 2:15:45 AM
Hi,

I want to concatenate multiple records of a column in a single field.like
I have data
num       id
123        1
456        1
765        1

i want to make a new table from this as
number                id
123,456,765         1

can anyone help me in this?

I m using ASP & SQL server

Reply By: Old Pedant Reply Date: 8/19/2008 2:57:01 PM
Please don't do this!

Make a query to produce a *RESULT* like that, yes.  But please don't create a new table like that.  You will lose the ability to make many kinds of good queries when you store data in a concatenated list like that.

Anyway:

This is a very general answer:
http://www.devcow.com/blogs/adnrg/archive/2005/10/03/SQL-Server-2000-Coalesce-lots-of-values-into-a-single-record.aspx

But if you only have a single ID value then you can do it more simply:
http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string

Go to topic 73506

Return to index page 1