Columns to Rows - Pretty please can someone help?

  • Hi There,

    I would like make it so that the Column Headers become the Row headers.

    I would also like to SUM each row

    Please can someone help me do this?

    CREATE TABLE #ZL_Calculation1

    (A_Flag VARCHAR,

    B_Flag VARCHAR,

    C_Flag VARCHAR,

    D_Flag VARCHAR,

    E_Flag VARCHAR,)

    INSERT #ZL_Calculation1 values

    ('1','1','1','0','1'),

    ('0','1','0','0','1'),

    ('0','1','0','1','0'),

    ('1','1','1','0','1'),

    ('0','1','0','0','1'),

    ('0','1','0','1','0'),

    ('1','1','1','0','1'),

    ('0','1','0','0','1'),

    ('0','1','0','1','0')

    I would like the results to look like this:

    A_Flag4

    B_Flag12

    C_Flag4

    D_Flag4

    E_Flag8

  • select

    title,

    sum(convert(int,flag))

    from (

    select * from @ZL_Calculation1

    )p

    unpivot

    (

    Flag for Title IN (a_flag,b_flag,c_flag,d_flag,e_flag)

    ) unpvt

    group by Title

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply