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)
 Hard time pivoting

Author  Topic 

ranalk
Starting Member

49 Posts

Posted - 2010-06-13 : 11:07:45
Hi,

I need help on pivoting the following table:



Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-13 : 22:20:41
[code]
select [Subject],
[Writing] = isnull([Writing], 0),
[Reading] = isnull([Reading], 0)
from yourtable t
pivot
(
sum([occurences])
for [System] in ([Writing], [Reading])
) p
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-14 : 03:54:35
For unknown number of Systems, use
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ranalk
Starting Member

49 Posts

Posted - 2010-06-14 : 10:39:35
Thank you guys !
Go to Top of Page
   

- Advertisement -