If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Concat multiple rows in one

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-27-07, 09:20
Marcelomrwin Marcelomrwin is offline
Registered User
 
Join Date: Dec 2007
Posts: 2
Red face Concat multiple rows in one

Hello friends, I need HELP...

I have the follow Table structure :

ID_CD
NM_CD
00019
TEXT001
00019
TEXT002
00019
TEXT003
00100
TEXT001
00100
TEXT002
00100
TEXT100
I need a SQL to do something like this:

ID_CD
NM_CD
00019
TEXT001,TEXT002,TEXT003
00100
TEXT001,TEXT002,TEXT100
Please.. someone can help me?
Reply With Quote
  #2 (permalink)  
Old 12-27-07, 09:49
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by Marcelomrwin
Code:
ID_CD NM_CD
00019 TEXT001,TEXT002,TEXT003
00100 TEXT001,TEXT002,TEXT100
To do this kind of "aggragate concatenation", you need to use recursive SQL; see, e.g., http://www.dbforums.com/showthread.php?p=4481846

I've recently given a presentation at IDUG on nested table expressions in DB2, which also gives this particular example use of CTEs -- see http://www.abis.be/resources/present...1106ctedb2.pdf
(pages 44-50).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #3 (permalink)  
Old 12-27-07, 09:53
Marcelomrwin Marcelomrwin is offline
Registered User
 
Join Date: Dec 2007
Posts: 2
Thank you Peter.. I will look your thread.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On