Getting Comma Separated list out of table records

Database

Getting Comma Separated list out of table records

Dear all,

 

I have table with data like

 

Part     Type

101      Pads

101      Disc

101      Sensor

102      Oil

103      Spark Plug

103      Glow Plug

104      Filters

 

and convert into like

Part    Type

101    Pads, Disc, Sensor

102    Oil

103    Spark Plug, Glow Plug

104    Filters

 

using select query.. I am using Teradat SQL Assistant 15.10

Any Idea? Please help me.

Vinay

 

 


Accepted Solutions
Teradata Employee

Re: Getting Comma Separated list out of table records

One option:

SELECT "Part", TRIM(TRAILING ',' FROM CAST(XMLAGG("Type"||',') AS VARCHAR(4096))) as "Types"

FROM myTable GROUP BY "Part";

1 ACCEPTED SOLUTION
2 REPLIES
Teradata Employee

Re: Getting Comma Separated list out of table records

One option:

SELECT "Part", TRIM(TRAILING ',' FROM CAST(XMLAGG("Type"||',') AS VARCHAR(4096))) as "Types"

FROM myTable GROUP BY "Part";

Re: Getting Comma Separated list out of table records

Thanks you so much fred. Its work like charm.

 

Regards

Vinay