Convert Columns To Rows

Posted on 2007-10-09
Last Modified: 2009-03-05
I have a table with 5 columns and 5 rows as below:

Comany      HeadcountStart      Starters      Leavers            HeatcountEnd
------      --------------                            --------      -------            ------------
AAA      500            10      5            505
BBB      180            5      0            185
CCC      225            15      5            235
DDD      50            3      0            53
EEE      200            0      5            195

I need to convert the data in the columns into rows as follows:

Company            AAA      BBB      CCC      DDD      EEE
HeadcountStart      500      180      225      50      200
Starters                           10      5      15      3      0
Leavers            5      0      5      0      5
HeadcountEnd      505      185      235      53      195

The number of rows and columns are static.

I'm using SQL 2000.

Thanks for help.
Question by:mrj1976
    LVL 27

    Accepted Solution


    There are many links to walk you through how to do pivot tables using SQL 2000 t-sql.
    LVL 23

    Assisted Solution

    by:Ashish Patel
    If the data is static then you can do this.

    Select 'HeadCountStart' As Company, 500 As AAA, 180 As BBB, 225 as CCC, 50 As DDD, 200 AS EEE
    Select 'Starters' As Company, 10 As AAA, 5 As BBB, 15 as CCC, 3 As DDD, 0 AS EEE
    LVL 6

    Expert Comment

    Here's a copy of the accepted solution which said was Force Closed:


    There are many links to walk you through how to do pivot tables using SQL 2000 t-sql.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now