JFrizz JFrizz - 1 month ago 5
SQL Question

Append column to view

enter image description here

I'm get this data from my view. I need to take the information and shift the different Amount Types into columns of their own. This can be done by creating a view for each type and combining them later into a single view. But is there a a way to do this all in a single view?

I was thinking about using subquery or union, but I am relatively new to this and not sure if it's the best course of action.

Answer

Try a pivot:

SELECT * 
FROM
(
    SELECT * 
    FROM [YOUR_VIEW]
) piv
PIVOT
(MAX(Amount) FOR Type IN ([401k], [Roth], [Employer Match]) thisshoudwork
Comments