Displaying rows in multiple columns

Posted by zizo on Stack Overflow See other posts from Stack Overflow or by zizo
Published on 2010-03-18T13:08:27Z Indexed on 2010/03/18 13:11 UTC
Read the original article Hit count: 394

Filed under:
|

Not sure if this is doable using sql alone or not, but here is the problem. I have a weird requirement that data needs to be displayed in columns so users can compare data quickly!

Here is what the result set looks like right now

CustomerID  Company     Active
001         ATT        Y
002         ATT        N
003         ATT        Y
001         VZ         Y
002         VZ         N
003         VZ         Y
001         TM         Y
002         TM         Y
003         TM         Y

Now this is how they want to see it

CustomerID  Company     Active      Company     Active      Company     Active
001        ATT         Y           VZ          Y            TM         Y
002        ATT         N           VZ          N            TM         Y
003        ATT         Y           VZ          Y            TM         Y

Assumptions:

  • This could be a pretty long table, that's why they want to see all companies on one row, rather than needing to scroll down to see if active or not.
    • Nummber of companies is between 1-3 in most cases

Any help is appreciated.

Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server