Pivoting partial table data

  • Hi all

    I have a table containing information looking like the below:

    Team Name EType Week Availability

    USA Chuck P 02/05/2011 3

    USA Ross P 02/05/2011 5

    UK Paul P 02/05/2011 5

    USA Chuck P 09/05/2011 5

    USA Ross P 09/02/2011 4

    UK Paul P 09/02/2011 5

    I am required to place the above information into another table looking like the below, using T-SQL:

    Team Name EType Week1 (which will be the week 02/05/2011) Week2

    USA Chuck P 3 (this is the availability for Paul for week 02/05/2011) 5

    USA Ross P 5 4

    UK Paul P 5 5

    From looking at the above datasets you can see the first three columns (Team, Name, EType) I have kept the same. However, I am required to flip/pivot the Date/Week and Availability columns

    Please can someone show me how to do this???

    Thanks in advance.

  • Check out the articles in my signature on Cross Tabs and Pivot Tables (Parts 1 and 2). This should give you all the information you need.

    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

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

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