Convert column data into row data

  • Hello,

    I have data like this in a table

    ID test_date Score

    001 4/1/2014 80

    001 5/4/2014 85

    001 6/1/2014 82

    I want to convert the data into a row like this:

    ID test_date1 score1 test_date2 score2 test_date3 Score3

    001 4/1/2014 80 5/4/2014 85 6/1/2014 82

    How can I do that with T-SQL?

    Thank you.

  • You can read the following articles about cross tabs:

    Part 1[/url]

    Part 2[/url]

    You might need to use ROW_NUMBER() to create "constant" values and MAX() to "aggregate" the data.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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