Convert rows into columns

  • I have 5 columns in my database. 1 column is coming like a dynamic.

    I want to convert records from rows to columns. Currently I have a data like this.

    Race AgeRange Amount

    W 17-20 500

    W 21-30 400

    W 31-40 200

    A 17-20 100

    H 41-50 250

    H 51-60 290

    So age range is not fixed and it can be any and I have one separate relational table for age range where it's coming from. Now I want to convert it into columns like

    Race 17-20 21-30 31-40 41-50 51-60

    W 500 400 200 0 0

    A 100 0 0 0 0

    H 0 0 0 250 290

    Thanks.

  • Duplicate post.

    All answers in here:

    http://www.sqlservercentral.com/Forums/Topic1634366-392-1.aspx

    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