Results 1 to 10 of 10
  1. #1
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21

    Append Query Question


    Every week I get a database dump with new and updated records for a table. The table maintains the same ID's so that the record may contain updated fields but the id never changes. So I get a few updated records and a few additional records. Rather then bringing this in as a new table every week, how could I make the append query, import the new table by overwriting the old table? I need this to be press of a button easy.

    Thanks

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Maybe a four step process

    Quote Originally Posted by chewbears View Post
    Every week I get a database dump with new and updated records for a table. The table maintains the same ID's so that the record may contain updated fields but the id never changes. So I get a few updated records and a few additional records. Rather then bringing this in as a new table every week, how could I make the append query, import the new table by overwriting the old table? I need this to be press of a button easy.

    Thanks
    1) Import the new replacement/additional info as Newdata.
    2) Run a query to delete a record from OlData if the OlData.ID=Newdata.ID
    3) Run a query to append NewData to OlData
    4) Delete Newdata

    While some SQL guru may be able to do it in one step, I would put those four steps in a macro which is connected to a button somewhere.

  3. #3
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Quote Originally Posted by hertfordkc View Post
    1) Import the new replacement/additional info as Newdata.
    2) Run a query to delete a record from OlData if the OlData.ID=Newdata.ID
    3) Run a query to append NewData to OlData
    4) Delete Newdata

    While some SQL guru may be able to do it in one step, I would put those four steps in a macro which is connected to a button somewhere.
    Not to be a complete newbie, but what would be the syntax for the delete query?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Quote Originally Posted by June7 View Post
    Why would it be a drop and not a delete?
    DELETE
    * FROM OlData
    WHERE NewData.ID = OlData.ID;

  6. #6
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Here is a tip

    Quote Originally Posted by chewbears View Post
    Not to be a complete newbie, but what would be the syntax for the delete query?
    -----------------------------------------------------------------------
    There is a reason that I'm an 18 year novice. I haven't bothered to learn SQL. Designing a query from scratch and combining queries have solved all of the problems I've come up against.

    In Access 2007, go to Create query, and bring in the OlData table and the newdata table. You need to create a join which gives you the records in Oldata which have ids in the newData.
    Once you've run that a few times and are satisfied with the result, click on the delete query button. If for some reason you need to runsql instead of openquery, after you have made it a delete query, choose SQL view.

    After you've done this a few times, you'll be able to understand SQL even though you may never speak it.

  7. #7
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Quote Originally Posted by hertfordkc View Post
    -----------------------------------------------------------------------
    There is a reason that I'm an 18 year novice. I haven't bothered to learn SQL. Designing a query from scratch and combining queries have solved all of the problems I've come up against.

    In Access 2007, go to Create query, and bring in the OlData table and the newdata table. You need to create a join which gives you the records in Oldata which have ids in the newData.
    Once you've run that a few times and are satisfied with the result, click on the delete query button. If for some reason you need to runsql instead of openquery, after you have made it a delete query, choose SQL view.

    After you've done this a few times, you'll be able to understand SQL even though you may never speak it.
    Thanks I have the two queries set up, but I am struggling making them work together. Forexample: I run the above SQL to delete. Works great. But when I do the append it doesn't look to the query result. It just looks at the 2 tables and appends. How do you make them work together?

  8. #8
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    Always listen to June7.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Sorry, I thought you needed to know how to remove the temporary NewData table/records.

    Delete from OlData based on records in NewData will be a little more complicated than your example. Check out DELETE FROM WHERE EXISTS
    http://www.techonthenet.com/sql/delete.php
    http://allenbrowne.com/subquery-01.html

    I've never had to use it, but have referred posters to this before.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Think I am catching on June:

    DELETE * FROM OlData
    WHERE EXISTS
    ( select *
    from NewData
    where NewData.ID = OlData.ID );

    Now just gotta make the append work after that fires.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Parent/Child Append Question
    By davidson12 in forum Access
    Replies: 6
    Last Post: 01-15-2015, 08:15 PM
  2. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  3. Append Query Question
    By JackA in forum Queries
    Replies: 5
    Last Post: 08-02-2011, 03:59 AM
  4. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  5. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums