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

    UPDATE Query puzzler

    I have two tables Bank & DTC... I need to update the bottom table (DTC) so that if a match is made both for the Store field and the Amount field that row gets updated with the "DTCdate" value in the bottom table is changed to match the "DateBank" value in the top table... any clues? Subquery needed?

    DateBank Store Amount
    9/9/2013 1 3,489.54
    9/5/2013 1 3,250.81
    9/9/2013 1 3,230.63
    9/16/2013 1 3,070.90
    9/23/2013 1 2,778.21
    9/26/2013 1 2,744.02


    9/20/2013 2 2,692.37
    9/16/2013 2 2,642.12
    9/23/2013 2 2,628.62


    DTCdate Store Amount
    9/6/2013 1 3,489.54
    9/7/2013 1 3,230.63
    9/11/2013 1 3,070.90
    9/20/2013 1 2,778.21
    9/24/2013 1 2,744.02
    9/18/2013 2 2,692.37

  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
    53,770
    Why do you need to do this? I see risk. What if there is more than one record with the same Amount for the same store?

    Seems to be a poor db design. What do these tables represent?
    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
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Here's your basic update query if there cannot be duplication of Store/Amount Combinations.
    Code:
    UPDATE DTC AS TD, Bank AS TB
    SET TD.DTCDate = TB.DateBank
    WHERE ((TD.Store = TB.Store)
    AND (TD.Amount = TB.Amount));
    If you know that there is a certain number of days lag typical, say 1-7 days, then you could do this to limit your exposure
    Code:
    UPDATE DTC AS TD, Bank AS TB
    SET TD.DTCDate = TB.DateBank
    WHERE ((TD.Store = TB.Store)
    AND (TD.Amount = TB.Amount)
    AND (TB.DateBank BETWEEN DateAdd("D",1,TD.DTCDate) AND DateAdd("D",7,TD.DTCDate))) 
    ;
    You might also add a beginning and ending date to the update, so you wouldn't be constantly recalculating last years' data.

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  2. Replies: 1
    Last Post: 05-17-2013, 12:53 PM
  3. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  4. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  5. Replies: 1
    Last Post: 08-19-2011, 12:16 PM

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