Results 1 to 5 of 5
  1. #1
    rickscr is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    21

    join date fields

    I'm building a database that stores research data from a reservoir. There are two tables of interest: DataValues and ReservoirElevations. The DataValues table has a LocalDateTime field, which contains the date and time of the observation in this format: mm/dd/yyyy hh:mm:ss AM/PM. The ReservoirElevations table has two fields: Elevation and MeasurementDate, with a date only (no time).



    Basically, I want to join these tables in a one-to-many relationship using their date fields. I'm thinking join in a query would be the way to go, but I can't seem to get it to work.

    What I've tried so far is to create a query that extracts the month, day, and year from LocalDateTime, then concatenates it. A 2nd query joins the first query to the ReservoirElevations table. This works initially, but then I get a "Data type mismatch in criteria expression" error.

    Any suggestions?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This type of thing should work, though the join can't be represented in design view, only SQL view:

    SELECT...FROM ReservoirElevations INNER JOIN DataValues ON ReservoirElevations.MeasurementDate = DateValue(DataValues.LocalDateTime)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Thinking about it further, you may find it simpler to create a query that pulls the data from DataValues and includes a new field using DateValue() on the date/time field. Then join the other table to that query in another query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    rickscr is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    21
    Quote Originally Posted by pbaldy View Post
    Thinking about it further, you may find it simpler to create a query that pulls the data from DataValues and includes a new field using DateValue() on the date/time field. Then join the other table to that query in another query.
    That works great. Thanks!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Date Fields
    By wali60 in forum Access
    Replies: 1
    Last Post: 03-28-2011, 06:58 PM
  2. SQL Inner Join where date = current date
    By Tyork in forum Queries
    Replies: 2
    Last Post: 11-07-2010, 02:07 PM
  3. Look for blank date fields
    By NOTLguy in forum Programming
    Replies: 3
    Last Post: 10-17-2010, 07:56 AM
  4. Default Date in Date Fields
    By rickn in forum Access
    Replies: 5
    Last Post: 04-14-2010, 01:30 PM
  5. Replies: 3
    Last Post: 08-06-2009, 11:49 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