JFrizz JFrizz - 1 year ago 68
SQL Question

Appending column to SQL view

Attached is a picture example of the data I'm getting out of my current view and what I am needing to produce. I need to take the information that is already contained in that view 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, however, I would like to know if there is a way to do this all in a single view. I was thinking subquery or union, but I am relatively new to this and not too sure on the syntax or what would work best. Thanks in advance if you can help!


Answer Source

Try a pivot, see below for example

      SELECT * 
    ) piv
    (MAX(Amount) FOR Type IN ([401k], [Roth], [Employer Match]) thisshoudwork
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download