Results 1 to 2 of 2
  1. #1
    Luffk73 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    1

    Selecting field based on effective date

    Hello,

    I am trying to create a query in Access 2010. I have 2 tables BU and Color. BU has employee ID, the BU the employee is assigned as of a date. The Color table has the employee ID, a color and a date. Based on the date in the Color table, I want to select the BU from the BU table. The query should bring in the BU that the employee was assigned to as of the date in the Color table.
    For example, if emplid 12345 was hired into BU abc as of 12/31/2013. Emplid 12345 was transferred to BU xyz on 1/15/2015. In the Color there are 2 rows for 12345. One with a date of 12/31/2014 and one with a date of 2/15/2015. I want the query to return abc on the row with the 12/31/2014 date and xyz on the row that contains 2/15/2015.


    Attached are the two tables. I have highlighted the expected results in yellow on the Color spreadsheet.

    Thanks

    Luffk73
    Attached Thumbnails Attached Thumbnails data.JPG  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Only solution I see uses domain aggregate:

    SELECT BU.*, Color.*
    FROM BU INNER JOIN Color ON BU.empID = Color.empID
    WHERE (((Color.[Date])=DMin("[Date]","Color","empID=" & [Bu].[empID] & " AND [Date]>=#" & [EffDate] & "#")));


    Date is a reserved word - should not use reserved words as names. Also advise to avoid spaces and special characters/punctuation (underscore is exception) in naming convention.
    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: 2
    Last Post: 05-22-2014, 06:11 PM
  2. Replies: 2
    Last Post: 12-27-2013, 05:20 PM
  3. Calculating a Bonus based on "effective date"
    By mpreston14 in forum Queries
    Replies: 2
    Last Post: 07-09-2013, 06:49 AM
  4. Replies: 1
    Last Post: 02-06-2011, 06:36 PM
  5. Selecting a corresponding table field based on text field.
    By michaeljohnh in forum Programming
    Replies: 5
    Last Post: 10-08-2010, 10:33 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