IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Concatenating rows in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rinkubhat

New User


Joined: 13 Sep 2005
Posts: 35
Location: India

PostPosted: Thu Feb 17, 2011 4:11 pm
Reply with quote

I Have table with two columns Employee Name and Age
I want to display all the employee names for a particular age in 1 row.
Table
Employee Name Age
ABC 20
XYZ 20
ERP 40
TRQ 40
AST 20

Result should be
Employee Age
ABC,XYZ,AST 20
ERP,TRQ 40

How can this be done in DB2
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Feb 17, 2011 5:43 pm
Reply with quote

by using google or forum search keywords "Concatenating rows in DB2"
Code:
select , replace(replace(cast(xml2clob(xmlagg(xmlelement(name X ,emp))) as varchar(200) ),'<X>','') ,'</X>',' ')
, age
from  tab1
group by age
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts How to compare two rows of same table DB2 11
Search our Forums:

Back to Top