Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2006
    Posts
    115

    Unanswered: "convert" a record from table A into table B

    Pls advise how to "convert" a record from table A into table B (to perform similar "transpose" function in excel)

    e.g a record in Table A with a key column & a number of data columns.
    key: 1
    col_1:A
    col_2:B
    col_3:C
    ...
    col_26:Z

    become in Table B with a key column & table A column name & data value.
    key col value
    1 col_1 A
    1 col_2 B
    ...
    1 col_26 Z

    thx

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    There are many ways to do this, and 99% of them are bad ideas from the perspective of database performance and maintenance. This appears to be heading toward an EAV model, which is a receipe for a disaster.

    Can you explain what your problem is in the real world (in other words what do you want to do instead of how you want to do it) so that we can help you find a way that is less work and much less frustrating?

    -PatP

  3. #3
    Join Date
    Jul 2006
    Posts
    115
    Quote Originally Posted by Pat Phelan
    There are many ways to do this, and 99% of them are bad ideas from the perspective of database performance and maintenance. This appears to be heading toward an EAV model, which is a receipe for a disaster.

    Can you explain what your problem is in the real world (in other words what do you want to do instead of how you want to do it) so that we can help you find a way that is less work and much less frustrating?

    -PatP
    actucally, i want to log the values changes between 2 tables with same columns and save the changes with column name into history table.
    e.g
    Table A
    key/col_1/col_2/.../col_x
    1/A/A/.../A

    Table B
    key/col_1/col_2/.../col_x
    1/A/B/.../A

    History table
    key/col_change/old_value
    1/col_2/A


    thx

  4. #4
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    I gotta tell ya, YMHO, that in my experience the best archiving strategy is just to save the whole record. Trying to reconstruct the state of a record at any point in time from a history table that is split out by columns would be a real pain.

    I actually have a script you can run that will cycle through your production tables and create a history table for each one, along with triggers for populating it. Runs in just a few minutes and voila'! Instant archiving.
    Let me know if you are interested in it.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'm interested even if the OP is not
    George
    Home | Blog

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Here ya go...no warranties or guarantees, and all that...
    Attached Files Attached Files
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you wrote one of those too.

    is anybody watching Battlestar Gallactica? Someday we will all meet and realize that we are all the same model of cylon.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  9. #9
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    triggers...yeah....
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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