Need to transpose columns data into row name with data.

  • Hi,

    I am having a requirement to transpose a column into rows data. My table structure is as:

    CandidateName   Subject    Marks

    --------------    --------    ------

    xyz                   sub1         10

    abc                   sub2         12

    aaa                   sub1          15

    sss                   sub6            60

    dss                   sub3           34

    ----                 ----             ---

    ----                --              ---

    I want a query which should show me the output as

    CandidateName     sub1       sub2           sub3     sub4  ... (the number of columns should be number of columns in first table)

    xzy                   10            18                12      23

    abc                  2            12                 12           23

    aaa                 --               34             44       44

    and so on...

     

     

  • Hi there,

    It sounds like you need a cross tab query (rows become columns and vice versa). The article here: http://www.sqlservercentral.com/columnists/plarsson/pivottableformicrosoftsqlserver.asp gives good coverage of how to achieve this in the various versions of SQL Server.

    - James

    --
    James Moore
    Red Gate Software Ltd

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

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