Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    65

    Unanswered: Really easy/dumb SQL question...

    Pardon me, my SQL knowledge is not advanced enough to know how to do this, though I'm sure it's pretty simple:

    Let's say I have a table called products, with fields like SKU, name, price. And let's say I have a temporary table with changes to be made (updates) to the current products.. same fields, SKU, name, price. I basically would like to be able to update currently existing entries in the products table, with the changes shown in the temporary table. Example:

    PRODUCTS:
    T231,Crazy Stick,4.99
    023J87,Basketball Hoop,12.99
    GB-572,CD Rack,8.99

    TEMP. TABLE:
    GB-572,Wooden CD Rack,8.99
    T231,Crazy Stick,3.95

    So I'd like to just merge the products in temp table w/ the ones in products. How can I do this?

    Thanks!

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    INSERT INTO PRODUCTS (SKU, name, price, etc)
    SELECT SKU, name, price, etc
    FROM #TEMP_TABLE
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jan 2004
    Posts
    65
    But wouldn't that insert them as new items, ignoring the current entries? I'd like to update the existing entries in the Products table...

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Oh... well you need to do an UPDATE statement then. Naturally there has to be some sort of common key involved. I assumed you needed an INSERT statement as there was no common key.

    General syntax:

    UPDATE yourTable
    SET yourTable.yourField = #temp.yourField, yourTable.field2 = #temp.field2
    FROM yourTable INNER JOIN #temp on yourTable.key=#temp.key
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Jan 2004
    Posts
    65
    Ahhh.. thanks a ton!!

Posting Permissions

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