locked
Select multiple rows as columns RRS feed

  • Question

  • User223678428 posted

    I have a need to take multiple rows of similar data and turn them into columns for a view.  I was wondering if this is possible and if it is, what would be the best way to do it?

    In the result below, Plan_ID is the unique identifier and Application_ID binds these together (and joins another table)

    How the data looks now:

    SELECT Plan_ID, Application_ID, PlanType, PlanPayment FROM Plans
    Plan_ID     Application_ID PlanType PlanPayment
    ----------- -------------- -------- -----------
    9           26             2        2
    10          26             2        2
    11          26             2        2
    12          26             2        2
    13          26             3        2

    Here's how I'd like it to look:

    Plan_ID9    Application_ID9 PlanType9 PlanPayment9 Plan_ID10   Application_ID10 PlanType10 PlanPayment10
    ----------- --------------- --------- ------------ ----------- ---------------- ---------- -------------
    9           26              2         2            10          26               3          1

    The Column names do not have to have the Plan_ID.  I just used that for visuals.  It could be Plan_ID1, 2, 3, etc.


    Wednesday, January 23, 2013 8:31 AM

Answers

All replies