sqlms-access

How do I assign a result depending on date using sql in access?


I have two tables: The first is a table of roles where each person is in a team but person c has changed teams in June:

enter image description here

The second is a table of signings where it has the name of who signed it and when it was signed.

enter image description here

What I need is some sql that will create a query that will connect the two tables and then show the team name of that person at the time of signing so signing 5 would be when person c was in team x, but signing 6 was when c was in team y. Potentially, but less important would be to also include ability to have Person d who doesn't exist in the role table so would need to show "not found" or blank


Solution

  • You can use this in SQL View of your query. I changed field names so they do not include spaces or reserved words:

    SELECT
        sgn.Signing,
        sgn.PName,
        sgn.DateOfSigning,
        ply.Team
    From Signing sgn
    Left Join Player ply on sgn.PName = ply.PName
    And sgn.DateOfSigning >= ply.StartDate
    And sgn.DateOfSigning < ply.EndDate