Query problem

J

Justin

I have entered the following SQL into a query as suggested by Tom
Ellison. When I try to run the query, I get the following error:

Invalid use of '.', '!', '()'. in query expression 'T1.[Truck No] =
T2.[Truck No] AND T1.[Date] = (SELECT MAX([Date]) FROM [Route Sheet]
T3 WHERE t3.[Truck No] = T1.[Truck No] AND t2.[Date] = (SELECT
MAX([Date]) FROM [Route Sheet] T4 WHERE T4.[Truck No] = T2.[Truck No]
AND T2.[Date] < T1.[Date]'.


SELECT T1.[Truck No], T1.Date AS Date1, T2.Date AS Date2, T1.[Ending
Mileage] AS Mileage1, T2.[Ending Mileage] AS Mileage2
FROM [Route Sheet] AS T1, [Route Sheet] AS T2
WHERE T1. [Truck No] = T2. [Truck No] AND T1. [Date] = (SELECT MAX
([Date]) FROM [Route Sheet] T3 WHERE T3. [Truck No] = T1.[Truck No])
AND T2. [ Date] = (SELECT MAX ([Date]) FROM [Route Sheet] T4 WHERE T4.
[Truck No] = T2. [Truck No] AND T2. [Date] < T1.[Date]);

Could someone point out where the problem is?

TIA
Justin
 
J

John Vinson

[Truck No] = T2. [Truck No] AND T2. [Date] < T1.[Date]);

Could someone point out where the problem is?

Right there. Blanks between T2. and [.

You should also change the name of the field Date. That's a reserved
word, and Access WILL get it confused with the Date() function.
 
J

Justin

John Vinson said:
[Truck No] = T2. [Truck No] AND T2. [Date] < T1.[Date]);

Could someone point out where the problem is?

Right there. Blanks between T2. and [.

You should also change the name of the field Date. That's a reserved
word, and Access WILL get it confused with the Date() function.

I guess that is why it now requests a parameter for "T2.Date"?
I'll rename this field and come back to the group if I have any other problems.

Thanks, John

Justin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top