update and insert help new to sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barflyz
    New Member
    • May 2010
    • 3

    update and insert help new to sql

    I have a table (table1) with a bunch of records say 50.

    this table has a code that is repeated in one column for the 50 records, example code is 123456

    I want to update/change code 123456 to a new code based on a list of distinct codes stored in a second table (table2) but evaluate and update one at a time, example below

    example: the first distinct code from table2 is code 456789, I want to take that code and update code 123456 in table1 to 456789 in table1 and then append these records from table1 to a 3rd table (table3)

    then repeat the process for each distinct code in table2,

    next code
    the second distinct code from table2 is code 666666, I want to take that code and update code 456789 in table1 to 666666 in table1 and then append these records from table1 to a 3rd table (table3)

    and repeat, repeat, repeat


    I know you have to use a variable and loop but not that sure how to accomplish.

    thanks
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Is your code in table1 unique?

    ~~ CK

    Comment

    • barflyz
      New Member
      • May 2010
      • 3

      #3
      Originally posted by ck9663
      Is your code in table1 unique?

      ~~ CK
      no it repeats for every record

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        So how are the two tables related? Could you post some sample data and tell us how it should look like after the update?

        ~~ CK

        Comment

        • barflyz
          New Member
          • May 2010
          • 3

          #5
          thanks but I think I am all set

          Comment

          Working...