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 |
evanburen
Posting Yak Master
167 Posts |
Posted - 2012-02-03 : 08:48:29
|
I'm experimenting with the PIVOT function for the first time and can't quite get this right. Here are my three tables and I want the results to look like this So far I have this (View_1 joins the 3 tables)SELECT ACS, SallieMae, FedLoanFROM (SELECT Servicer, Comments, Status, MeasureFROM View_1) upPIVOT (MAX(MEasure) FOR Servicer IN (ACS, SallieMae, FedLoan)) AS pvtbut it looks like this The number of Servicers (ACS, SallieMae, FedLoan) is fixed but the number of Measures (SDCL, Call Monitoring etc) is variable |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-03 : 09:41:13
|
[code]SELECT *FROM(SELECT s.Servicer,m.Measure,c.CommentsFROM Service sINNER JOIN Comments cON c.ServiceID = c.ServiceIDINNER JOIN Measures mON m.MeasureID = c.MeasureID)tPIVOT(MAX(Comments) FOR Servicer IN (ACS, SallieMae, FedLoan))p[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|