Rows to Columns

  • Good morning all

    I have a table that looks like this:

    Count Bin Date

    1 2AA 25/09/2010

    2 2AA 03/10/2010

    3 2AA 09/10/2010

    1 3BC 03/08/2010

    2 3BC 04/09/2010

    3 3BC 01/10/2010

    etc.

    What I need is the following:

    Bin 1 2 3

    2AA 25/09/2010 03/10/2010 09/10/2010

    3BC 03/08/2010 04/09/2010 01/10/2010

    etc.

    Is this at all possible?

    Regards

    Jean

  • Have a look in BOL at the PIVOT function, might do the trick for you.

  • Take a look at the articles linked to in my signature under Cross-Tabs and Pivots, Part 1 and Part 2.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks Wayne

    Problem solved!

  • grahamc (10/8/2010)


    Have a look in BOL at the PIVOT function, might do the trick for you.

    As a side bar, you might want to take a look at the two articles Wayne spoke of in his post. There's a pretty good speed advantage to using a good ol' fashioned Cross-Tab instead of a Pivot.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply