Converting the ROW values as Columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phanikumar32
    New Member
    • Apr 2014
    • 22

    Converting the ROW values as Columns

    Hai all,
    I have a table like below.(with the column headings are column1 and column2)
    Column1 Column2
    id 2
    Name xyz
    Class 10
    id 3
    Name pqr
    Class 10
    id 5
    Name def
    Class 10

    So for this above table i want the OutPut as below.
    id Name Class
    2 xyz 10
    3 pqr 10
    5 def 10

    can any one help me how i will get this.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That's impossible to do unless you have some sort of unique sequential number to put each row in the original source in the right order.

    Comment

    • phanikumar32
      New Member
      • Apr 2014
      • 22

      #3
      Thanks Rabbit for your response.
      So is it possible if the 'id' values are in sequence order.
      If possible how i can get.
      Actually for my output i made a query using the 'PIVOT' function,but
      it displays the output as
      id Name Class
      2 xyz 10

      (OR)

      id Name Class
      5 def 10

      Because the 'PIVOT' function is want the Aggregate function.so that's why it giving the details for id=2 or id=5
      Not showing the entire values what i want.
      so can you please tell me for getting the all values if the 'id's are in sequence order.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        If you have an ID in sequential order, you join the table to itself 3 times on the ID to the next ID in the sequence.

        Comment

        Working...