Results 1 to 6 of 6
  1. #1
    BrockWade is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Posts
    63

    Query to exclude items from another table


    I am trying to write a query that will update a table (tmpChangeOrders) but exclude records that have a value in the table to be updated (tmpChangeOrders.ConcatenateBank) that match another table's values (tmpJournalEntryChangeOrders.Concatenate)... the following query does not work.... any ideas?.... Thanks!!

    INSERT INTO tmpChangeOrders ( Store, Amount, ConcatenateBank, TransactionDate )
    SELECT DISTINCT tmpBank.Store, tmpBank.Amount, [tmpBank].Store & " " & [tmpBank].Amount AS ConcatenateBank, Format([tmpBank.TransactionDate],"mm/dd/yy") AS TransactionDate
    FROM tmpBankDebits LEFT JOIN tmpBank ON tmpBankDebits.[ConcatenateBankDebits] = tmpBank.ConcatenateBank

    WHERE tmpChangeOrders.ConcatenateBank NOT IN (SELECT tmpJournalEntryChangeOrders.Concatenate);

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You want to select records from tmpBank where Store&Amount value not in tmpChangeOrders? Try including tmpChangeOrders in the SELECT DISTINCT statement joined to tmpBank.
    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.

  3. #3
    BrockWade is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Posts
    63
    I'm sorta confused... won't that mismatch the number of values to insert by adding tmpChangeOrders to the SELECT DISTINCT statement?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I don't know why but then I don't know anything about your data structure. Regardless, the filter criteria needs to be in the SELECT DISTINCT subquery and since you are using a field from tmpChangeOrders to filter on, that's where the table needs to be.

    Because a WHERE clause in an INSERT sql makes no sense. Need to filter the SELECT recordset.
    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
    BrockWade is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Posts
    63
    I have a table tmpChangeOrders with four fields: Store, Amount, ConcatenateBank, TransactionDate.

    I need to fill this table with the contents of the table tmpBank with its fields: Store, Amount, ConcatenateBank, TransactionDate.

    But I have a third tmpChangeOrders with three fields: Store, Amount, Concatenate.

    I need to keep any records in tmpBank with a matching Concatenate/ConcatenateBank value from filling into the tmpChangeOrders file.

    I'm really in the dark about how to do this. My original query below was doing its job fine until the new challenge came up:

    INSERT INTO tmpChangeOrders ( Store, Amount, ConcatenateBank, TransactionDate )
    SELECT DISTINCT tmpBank.Store, tmpBank.Amount, [tmpBank].Store & " " & [tmpBank].Amount AS ConcatenateBank, Format([tmpBank.TransactionDate],"mm/dd/yy") AS TransactionDate
    FROM tmpBankDebits LEFT JOIN tmpBank ON tmpBankDebits.[ConcatenateBankDebits] = tmpBank.ConcatenateBank

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Build the SELECT query as I described and save it.

    Build INSERT query that references the first query in SELECT subquery.

    If still need help, provide db for analysis. Follow instructions at bottom of my post.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-12-2013, 01:38 PM
  2. Replies: 3
    Last Post: 04-13-2012, 10:39 AM
  3. Replies: 1
    Last Post: 06-08-2011, 04:43 AM
  4. Listing all items from a table in a form
    By Ddwinters45 in forum Forms
    Replies: 1
    Last Post: 01-13-2011, 03:29 PM
  5. Add Items from Form to table
    By swalsh84 in forum Forms
    Replies: 6
    Last Post: 06-14-2010, 06:53 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