Pivot Query

  • I Have a table "DemoPRofile" as shown below

    dPId demoNo MTrip FTrip

    10000MA021 1 0.52240 0.4314

    10000MA021 2 0.0066 0.0102

    10000MA021 3 0.0116 0.0076

    10000MA021 4 0.0057 0.0041

    10000MA007 1 0.0455 0.9932

    10000MA007 2

    Output required:

    DPID MTRIP1 FTRIp1 mTRIP2 FTRIP2 MTRIP3 FTRIP3 MTRIp4 FTRIp4

    10000MA021 0.52240 0.4314 0.0066 0.0102 0.0116 0.0076 0.0057 0.0041

  • Hi,

    you could either use (dynamic) Cross Tabs or the PIVOT function.

    Dynamic cross tabs are used if you don't have a fixed number of target columns.

    Please read the following two articles by Jeff Moden.

    Cross Tabs and Pivot[/url]

    Dynamic Cross Tabs[/url]

    If you need further assistance please provide sample data as described in the link in my signature.

    @jeff (if you come across: just added another plug post) 🙂



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • AWESOME.

    Thanks for the info and it solved my problem.

    Thank you .

    Sree

  • You're welcome.

    (Even though I didn't add any information that I came up with. So, all the flowers belong to Jeff 🙂 )



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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