Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    16

    Unanswered: Can this be done??? Multiple rows to Multiple Columns

    I have a table that holds 3 fields:

    PartNumber ( Char 25 )
    Date ( Char 6 )
    QtySold ( Integer )

    The date is a representation of month year ( so 012011 would mean Jan 2011 ).

    So a sample would be

    A | 122010 | 5
    A | 112010 | 4
    A | 092010 | 7
    A | 082010 | 6
    B | 112010 | 5
    B | 102010 | 4
    B | 072010 | 7
    B | 062010 | 6
    C | 122010 | 5
    C | 102010 | 11
    C | 082010 | 9
    C | 062010 | 3


    What I need to see is 1 row for Part A - that shows all items - one row for b etc...

    I can think of doing this manually with a bunch of case entries ( for each month )

    But i'm wondering if there is an easier way...

    What I want as a result is something like either:
    Code:
    A | 122010 | 5 | 112010 | 4 | 092010 | 7 | 082010 | 6
    B | 112010 | 5 | 102010 | 4 | 072010 | 7 | 062010 | 6
    C | 122010 | 5 | 102010 | 11 | 082010 | 9 | 062010 | 3
    OR
    Code:
    # | 122010 | 112010 | 102010 | 092010 | 082010 | 072010 | 062010 |
    A | 5      | 4      | 0      | 7      | 6      | 0      | 0      |
    B | 0      | 5      | 4      | 0      | 0      | 7      | 6      |
    C | 5      | 0      | 11     | 0      | 9      | 0      | 3      |
    Any help is greatly appreciated!

    Chris

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by dockraz View Post
    Can this be done??? Multiple rows to Multiple Columns
    can this be done??? not easily, no

    should this be done??? not in SQL, no
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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