Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: Transposing Data In A Table

    Hi,

    I am trying to write a query to change the data that looks like below:

    ID FEE1 FEE2 FEE3 FEE4
    -- ---- ---- ---- ----
    1 10 20 30 40
    2 11 21 31 41
    3 12 22 32 42

    I want the above table data to be transformed to the below format in another table.


    ID Amount FEEType
    -- ------- ------
    1 10 FEE1
    1 20 FEE2
    1 30 FEE3
    1 40 FEE4
    2 11 FEE1
    2 21 FEE2
    2 31 FEE3
    2 41 FEE4
    3 12 FEE1
    3 22 FEE2
    3 32 FEE3
    3 42 FEE4

    Basically I want to change a horizontal table to a vertical table.
    I know a repetitive way of using Select and Insert. But I want to write a procedure as in the table that I am using it has about 80 fee fields. Can anybody help me with the SQL Code for the procedure?

    Thank you.

  2. #2
    Join Date
    Oct 2003
    Posts
    13
    You have to write a cursor for this -

    open cursor for all the rows
    for each row
    --- check for fee1
    ------ insert into temptable
    --- check for fee2
    ------ insert into temptable
    --- check for fee3
    ------ insert into temptable
    --- check for fee4
    ------ insert into temptable
    close cursor
    select * from temptable

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •