Use Sum()
of the DateDiff()
expression to avoid the "does not include the specified expression ... as part of an aggregate function" complaint.
SELECT
ROOM.HotelNo,
Sum(
DateDiff(
"d",
[ArrivalDate],
[DepartureDate]
) * ROOM_TYPE.RoomRate
) AS TotalRevenue
The WHERE
clause includes DepartureDate > Now()
, which I suspect filters the results to those which have not yet departed. I think you want <
instead of >
there.
Consider using INNER JOIN
instead of using the WHERE
clause to specify how rows from the tables are matched. If you can build this query from Design View of the Access query designer, setting up the joins will be easy. And the query designer knows the rule about required parentheses when joining more than 2 tables ... so will produce SQL which keeps the db engine happy.