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)
 Create one row from two

Author  Topic 

oasis1
Starting Member

35 Posts

Posted - 2010-09-08 : 10:53:19
I have to merge two rows together into one.

I have a table that looks like this

Dept Year Percentage
MOA 2009 40
MOA 2010 35
HON 2009 64
WAI 2010 27


I need the final output to look like this
Dept 2009 2010
MOA 40 35
HON 64 N/A
WAI N/A 27

Mahalo for your help.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-09-08 : 22:16:54
[code]
select *
from yourtable
pivot
(
max(Percentage)
for Year in ([2009], [2010])
)p
[/code]


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

Go to Top of Page
   

- Advertisement -