Here I am back again with this issue. @Ratslinger has helped previously and I have studied SQL and using joins but still am not able to achieve what I want, maybe it’s not possible, I would like to know.
The DB is a simple record of trips and accommodation. When I arrive I record the details and again on departure. So the next record entry form should be able to present me with departure details from the last record, date, time and odometer. The form then should be able to show the trip time and distance traveled in calculated fields.
Surely it should not be necessary to enter these details again in a new record only the details of the accommodation, arrive - date, time and odometer, and depart - date, time and odometer. The trip details - time and odometer should be able to be calculated and presented on the form. I have struggled with designing a query in SQL which will retrieve records from the previous record, could not figure how to use previous, top etc.
DB Attached and pic of the form and what I want to achieve.
Here’s hoping
Mike
Edit 16:28 02/01/2018
Reply from Ratslinger ( 1 hour ago )
First, by what was presented in the
sample I should have simply waited for
you to post something with somewhat
correct information. Etc
Sample ------ FromMycle2.odb
I attempted to calculate the trip time but my understanding of SQL is limited. Am I getting close with the code below. I get a syntax error, after checking the Datediff Function I’m unsure if it should be
Datediff(‘hh’ “B”.“DepartTimePrior”,“ArriveTime”) “TripTime”
Or
Datediff(‘hour’ “B”.“DepartTimePrior”,“ArriveTime”) “TripTime”
Thanks
Mike
SELECT “TripSectorID”, “PrevAccom”,Datediff(‘hour’ “B”.“DepartTimePrior”,“ArriveTime”) “TripTime” , “ArriveOdom” - “B”.“DepartOdomPrior” “SegMileage”, “B”.* FROM “TripSectors” “A” LEFT JOIN ( SELECT “TripSectorID” “TripSectorIDPrior”, “AccommodationID” “AccommodationIDPrior”, “ArriveDate” “ArriveDatePrior”, “ArriveTime” “ArriveTimePrior”, “ArriveOdom” “ArriveOdomPrior”, “DepartDate” “DepartDatePrior”, “DepartTime” “DepartTimePrior”, “DepartOdom” “DepartOdomPrior”, “PrevAccom” “PrevAccomPrior” FROM “TripSectors” ) “B” ON “A”.“PrevAccom” = “B”.“AccommodationIDPrior”
Edited as requested @Ratslinger
Edit 17:06 02/01/2018
@Ratslinger 8 min ago
As for the SQL, you need to use the
syntax for the database in use. For
the HSQLDB v1.8 embedded it is:Datediff(‘hour’,
“B”.“DepartTimePrior”,“ArriveTime”)
“TripTime” Note the comma after
‘hour’.