SQL Server Pivot on multiple fields

Viewed 5636

I have searched this website for all possible solutions but still can't find an answer for my Pivot problem.

I have a table with the following data.

Portfolio  |  Date      |  TotalLoans  | ActiveLoans  | TotalBalance
--------------------------------------------------------------------
P1         | 2015-12-31 |       1,000  |         900  |   100,000.00
P1         | 2015-11-30 |       1,100  |         800  |   100,100.00
P1         | 2015-10-31 |       1,200  |         700  |   100,200.00

I am trying to create a pivot with the following output (only where Portfolio = P1)

Field        | 2015-12-31 | 2015-11-30 | 2015-10-31 |
-----------------------------------------------------
TotalLoans   |      1,000 |      1,100 |      1,200 |
ActiveLoans  |        900 |        800 |        700 |
TotalBalance |    100,000 |    100,100 |    100,200 | 

Ideally, I am looking for a dynamic pivot, but a static query would do as well and I can try a dynamic query out of that.

4 Answers
Related