Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Concatenating rows in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Concatenating rows in DB2
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: 1278
Location: Belgium

PostPosted: Thu Feb 17, 2011 5:43 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts Can we use OPTIMIZE FOR 1 ROWS for fe... cvijay784 DB2 1 Fri Aug 05, 2016 11:56 am
No new posts Column into multiple rows V S Amarendra Reddy SYNCSORT 2 Thu Mar 03, 2016 8:22 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us