Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Unanswered: convert the rows of data into columns in db2

    Hi,

    In db2 I want to write a sql that can take the values from a table which has multiple rows in it and want to consolidate them to another table with multiple columns.

    for example the table data from table A is as follows

    column contract column value
    1-A 25
    1-A 50
    1-A 75
    1-B 15
    1-B 20
    ...

    then the table b should look like as follows -

    col1 col2 col3 col4
    1-A 25 50 75
    1-B 15 20 -
    .....


    how do I do this in db2?

  2. #2
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    google :
    db2 pivot unpivot table
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Or search this forum with "recursive query".

  4. #4
    Join Date
    Feb 2009
    Posts
    2
    Quote Originally Posted by rahul_s80
    google :
    db2 pivot unpivot table

    Can you please help me with the desired query .. I looked for the example given on one of the site, but that has 3 cols and based on value of 2nd col he is picking up value of third.
    In my case , I only have two cols as given ...

  5. #5
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    ... but that has 3 cols and based on value of 2nd col he is picking up value of third.
    In my case , I only have two cols as given ...
    You can pick up value of 2nd col based on value of 2nd col.

Posting Permissions

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