Results 1 to 6 of 6
  1. #1
    breakingme10 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Oklahoma
    Posts
    153

    add time in to a date sorted subquery

    Code:
    PriorOdometer: (SELECT MAX([odometerMiles]) FROM [FuelCards] AS [PreviousCards] 
    WHERE [PreviousCards].[fuelDate] < [FuelCards].[fuelDate], 
    AND [PreviousCards].[truckNumber] = [FuelCards].[truckNumber])
    I got this subquery to work to insert a field called PreviousOdometer that would enter in the record before its odometer mileage. but my records also have a fuelTime field because most trucks are filled up in the morning and the evening. so I will have two dates that are the same but separate times.

    I am terrible at sql and have no idea how to add in the time field.

    Can anyone help me?

  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,641
    I would have the date and time in a single field, but this should work:

    WHERE [PreviousCards].[fuelDate] + [PreviousCards].[fuelTime] < [FuelCards].[fuelDate] + [FuelCards].[fuelTime]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    breakingme10 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Oklahoma
    Posts
    153
    Well some of the drivers don't fill in anything but the truck date and gallons so i'm going to have a hell of a time with this.

  4. #4
    breakingme10 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Oklahoma
    Posts
    153
    Not sure whats wrong but i keep getting a syntax error

    Code:
    PriorOdometer: (SELECT MAX([odometerMiles]) FROM [FuelCards] AS [PreviousCards] WHERE ([PreviousCards].[fuelDate] + [PreviousCards].[fuelTime]) < ([FuelCards].[fuelDate] + [FuelCards].[fuelTime]), 
    AND [PreviousCards].[truckNumber] = [FuelCards].[truckNumber])
    i tried it without the fueldate+fueltime in parenthesis too. still error.

  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,641
    The comma for starters:

    Code:
    PriorOdometer: (SELECT MAX([odometerMiles]) FROM [FuelCards] AS [PreviousCards] WHERE ([PreviousCards].[fuelDate] + [PreviousCards].[fuelTime]) < ([FuelCards].[fuelDate] + [FuelCards].[fuelTime]), 
    AND [PreviousCards].[truckNumber] = [FuelCards].[truckNumber])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    breakingme10 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Oklahoma
    Posts
    153
    not sure why that comma made such a huge difference considering that the previous code worked for date and it had the comma but i remove the comma and now it works.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-13-2014, 07:23 PM
  2. Replies: 1
    Last Post: 07-13-2012, 08:53 AM
  3. X-axis graph must be sorted by date and time!
    By technesurge in forum Reports
    Replies: 1
    Last Post: 06-29-2012, 01:46 PM
  4. Multiple Entries sorted by date
    By l3111 in forum Forms
    Replies: 1
    Last Post: 12-12-2011, 11:41 AM
  5. Access Subquery Max Date/Time field
    By ruci1225 in forum Access
    Replies: 1
    Last Post: 04-08-2011, 07:33 AM

Tags for this Thread

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