Converting Rows to Columns

  • I have a table that I need to convert the rows into columns for display purposes. Are there any good articles/how to's on how to do this?

    Thanks,

    Kyle

  • This is known as a crosstab query,

    Lots of examples on this site,

    Use Case statement, and probably a group by clause

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_14_04j7.asp

    If you post your actual table, some sample data, and desired output you'll get a quick response for your query.

  • Look into Pivot Table conecpts in Books Online for SQL. You will get a fair idea on converting rows to columns. Also look at CUBE and ROLLUP operators for more help.


    Kindest Regards,

    Vannela

  • CUBE and ROLLUP concepts are more appropropriate for Datawarehousing related activities and are far more advanced to use for simple pivoting activities. All you will need is to understand how to use the CASE WHEN THEN END statement and GROUP BY the common column and that should solve your purpose. If the columns you are trying to make rows into are numeric, then you might need to SUM them to make them part of a GROUP.

     

    Hope this helps.

    Tony John.

Viewing 4 posts - 1 through 3 (of 3 total)

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