change table format from row to cloumner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    change table format from row to cloumner

    i have a table in format
    item_id packet_no
    1 4
    1 5
    2 6
    3 7
    3 8
    3 9
    4 10
    4 11
    i want to convert it into this format
    item_id packet_1 packet_2 packet_3
    1 4 5
    2 6
    3 7 8 9
    4 10 11
    is it possible by sql query?
    kindly help
    thanx
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Yes.

    Checkout the PIVOT clause.

    Happy Coding!!!


    ~~ CK

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      If you have 2005 or later, you'll want to use the row_number() function before the pivot. If you have an earlier version, you'll want to use a ranking query before the pivot.

      Comment

      Working...