Results 1 to 5 of 5
  1. #1
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51

    Append query that checks if value exists before appending


    Hello

    I'm trying to run an append query, but it should only append the rows which are not already present.

    Code:
    INSERT INTO NySaneringsData ( DelledningsID, SaneringsmetodeKode )
    SELECT SaneringsprojektImport.DelledningsID, SaneringsprojektImport.SaneringsmetodeKode
    FROM NySaneringsData RIGHT JOIN SaneringsprojektImport ON NySaneringsData.DelledningsID = SaneringsprojektImport.DelledningsID 
    WHERE (((SaneringsprojektImport.SaneringsmetodeKode) Is Not Null) AND ((Exists (SELECT * FROM NySaneringsData WHERE NySaneringsData.SaneringsmetodeKode = SaneringsprojektImport.SaneringsmetodeKode))=False)) 
    ORDER BY SaneringsprojektImport.DelledningsID;
    I got the above code, which gives the following result: http://imgur.com/kFZZhKb

    For some reason not all values are displayed.

    Any help would be much appreciated.
    Last edited by FoolzRailer; 08-08-2016 at 02:54 AM. Reason: Edited to new code.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    If the table is keyed, adding records will reject duplicates.
    If not,
    build a query to pull records that DO NOT exist in target and but do in source. (An outer query)
    The make it an append query.

  3. #3
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51
    Thanks for the reply!

    The table isn't keyed, so I would need to build two queries, in order to do what I want?

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,699
    Try the NOT Exists, and you won't need the =False

    Code:
    ((NOT Exists (SELECT * FROM NySaneringsData WHERE NySaneringsData.SaneringsmetodeKode = SaneringsprojektImport.SaneringsmetodeKode))))

  5. #5
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51
    The below code does the trick

    Code:
    INSERT INTO NySaneringsData ( DelledningsID, SaneringsmetodeKode )
    SELECT SaneringsprojektImport.DelledningsID, SaneringsprojektImport.SaneringsmetodeKode
    FROM SaneringsprojektImport
    WHERE (((SaneringsprojektImport.SaneringsmetodeKode) Is Not Null) AND ((Exists (SELECT * 
    FROM NySaneringsData 
    WHERE NySaneringsData.SaneringsmetodeKode = SaneringsprojektImport.SaneringsmetodeKode
    AND NySaneringsData.DelledningsID = SaneringsprojektImport.DelledningsID
    ))=False));

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

Similar Threads

  1. Replies: 1
    Last Post: 04-10-2016, 09:50 AM
  2. Replies: 10
    Last Post: 10-30-2013, 02:06 PM
  3. Replies: 1
    Last Post: 03-13-2013, 10:37 PM
  4. Replies: 4
    Last Post: 12-14-2012, 06:33 PM
  5. Replies: 7
    Last Post: 07-21-2011, 01:01 PM

Tags for this Thread

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