Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Horizontal to Vertical

Author  Topic 

ranalk
Starting Member

49 Posts

Posted - 2010-02-21 : 09:25:24
Hi,

I need (desperately) to change a SQL result from Horizontal view to vertical.
the current table looks like this:

However, i would like it to be three columns (Subject, API_Live, Live).
The subject column will have all the titles (UpdatePlayerBalance,GetPlayerBalance etc.).
Thanks a lot.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-21 : 09:31:26
[code]
SELECT Subject,API_LIVE,LIVE
FROM
(
SELECT EnvironmentDescription,Subject,Value
FROM Table t
UNPIVOT (Value FOR Subject IN ([UpdatePlayerBalance],[GetPlayerBalance],...,[Timeouts]))u
)m
PIVOT (SUM(Value) FOR EnvironmentDescription IN ([API_LIVE],[LIVE]))p
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ranalk
Starting Member

49 Posts

Posted - 2010-02-21 : 10:23:12
Thanks a lot visakh !
It works perfectly.
Besides, your blog is nice.

Thanks again.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-21 : 10:25:50
quote:
Originally posted by ranalk

Thanks a lot visakh !
It works perfectly.
Besides, your blog is nice.

Thanks again.


Welcome
Thanks

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -