Query to change rows as columns

  • Hi,

    I have table like

    Name Type Cost

    ABTRAVELSIndica:4 88284.5833333333

    ABTRAVELSLuxury Bus:180

    ABTRAVELSSumo:6 27037.3333333333

    ABTRAVELSTavera:8 50

    I want result like

    Indica:4 Luxury Bus:18 Sumo:6Tavera:8

    ABTRAVELS 88284.5833333333 0 27037.3333 50

    Please suggest any query for this

    Regards,

    Balu Reddy K

  • Hi,

    You might check pivot: Using PIVOT and UNPIVOT

  • balu-1123884 (2/8/2012)


    Hi,

    I have table like

    Name Type Cost

    ABTRAVELSIndica:4 88284.5833333333

    ABTRAVELSLuxury Bus:180

    ABTRAVELSSumo:6 27037.3333333333

    ABTRAVELSTavera:8 50

    I want result like

    Indica:4 Luxury Bus:18 Sumo:6Tavera:8

    ABTRAVELS 88284.5833333333 0 27037.3333 50

    Please suggest any query for this

    Regards,

    Balu Reddy K

    Read this article then post your data and DDL in a readily usable fashion. Help us to help you!! Everyone here is an unpaid volunteer, you are much more likely to get working, tested code if you post readily consumable data and DDL.[/url]

    Thanks.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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