Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    2

    Red face Unanswered: 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?

  2. #2
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    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/

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    Thank you Peter.. I will look your thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •