Help me in writing the Query

  • hI I have some problem in displaying this data.....can you please help in writing the query

    Below is the data which i have in the table

    RID DISCNT DISPAID

    8446112 P1 67.306

    844622 p2 667.6

    844634 p3 5667.03

    844646 p4 6667.96

    8446523 M1 6467.3

    844662 M2 6637.36

    844671 M3 6637.6

    I want to display this data into this format

    RID p1 p2 p3 p4 m1 m2 m3 total

    84461 12-67.306 X X X X 21-33.6 X 33-100

    ramdin

  • Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    On SQL 2005, take a look at the PIVOT keyword. It may do what you want.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The Pivot operation should do what you need. Take a look at that one.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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