Home All Groups Group Topic Archive Search About

to group attribute values of the same id together with sql?

Author
22 Jul 2005 3:29 AM
roy
Suppose I have a table like this
--------------
ID Attribute
1  A
2  B
2  C
3  D
3  E
3  F
--------------

How to write a sql query to convert the above table into
--------------
ID NewAttribute
1  A
2  B, C
3  D, E, F
--------------

Thanks a lot.
Roy

Author
22 Jul 2005 4:14 AM
Anith Sen
There are no built-in operators in t-SQL which does such concatenations and
hence it is recommended that you use a client side programming language to
generate such resultset. To do this in t-SQL, you can find examples of some
kludgy approaches at:
http://groups-beta.google.com/group/microsoft.public.sqlserver.programming/msg/2d85bf366dd9e73e

--
Anith
Author
22 Jul 2005 6:40 AM
Srikanth
Hi Roy,

Check this URL which help to solve you.

http://www.sqlteam.com/item.asp?ItemID=256

Regards,
Srikanth Raavilla

Show quote
"roy" <royl***@hotmail.com> wrote in message
news:1122002991.229177.14340@o13g2000cwo.googlegroups.com...
> Suppose I have a table like this
> --------------
> ID Attribute
> 1  A
> 2  B
> 2  C
> 3  D
> 3  E
> 3  F
> --------------
>
> How to write a sql query to convert the above table into
> --------------
> ID NewAttribute
> 1  A
> 2  B, C
> 3  D, E, F
> --------------
>
> Thanks a lot.
> Roy
>

AddThis Social Bookmark Button