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.
| Author |
Topic |
|
andykn
Starting Member
12 Posts |
Posted - 2010-01-17 : 13:36:46
|
| I have a table showing which apps are installed on which computers and a report of software installed on computers:Comp1 App1Comp1 App2Comp1 App3Comp2 App1Comp2 App3and so onWhat I want isComp1 Comp2App1 App1App2 App3App3And I can't for the life of me think how do do it. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-01-17 : 21:04:11
|
[code]declare @apps table( comp varchar(5), app varchar(5))insert into @appsselect 'Comp1', 'App1' union allselect 'Comp1', 'App2' union allselect 'Comp1', 'App3' union allselect 'Comp2', 'App1' union allselect 'Comp2', 'App3'; with dataas( select *, row_no = row_number() over (partition by comp order by comp, app) from @apps)select [Comp1], [Comp2]from data pivot ( max(app) for comp in ([Comp1], [Comp2]) ) p[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
andykn
Starting Member
12 Posts |
Posted - 2010-01-20 : 14:26:06
|
| Thanks very much KH.This was just what I needed. |
 |
|
|
|
|
|