ShabanaHafiz
Programmer
I asked this question in another thread of mine, thread701-1365250, but could not get reply. May be because it was in continuation of my previous question and I should have avoided asking multiple questions in a single thread. So, I am writing my question again in this new thread.
I am using Microsoft Access 2003.
In an Access Query, I have one table and one query; LogBook, VHCostPerKM (Vehicle Cost Per KM).
Fields in LogBook table are:
ProjectID
OfficeID
VehicleID
DateOfTravel
KMBeforeTravel
KMAfterTravel
Fields in VHCostPerKM query are:
OfficeID
VehicleID
UnitCost
For a given DateOfTravel, I need to calculate for each ProjectID, OfficeID and VehicleID the following:
Sum of KM Traveled
Cost per Project
The SQL View of my query is as follows:
I also need to show description in place of ProjectID, OfficeID and VehicleID.
I added Project table and replaced ProjectID with Description field of Project Table. This worked fine and at this stage, SQL View was as follows:
Then I added Office table and replaced OfficeID with Description field of Office Table. When I executed the query this time, Office column appeared blank. At this stage, SQL View was as follows:
I am using Microsoft Access 2003.
In an Access Query, I have one table and one query; LogBook, VHCostPerKM (Vehicle Cost Per KM).
Fields in LogBook table are:
ProjectID
OfficeID
VehicleID
DateOfTravel
KMBeforeTravel
KMAfterTravel
Fields in VHCostPerKM query are:
OfficeID
VehicleID
UnitCost
For a given DateOfTravel, I need to calculate for each ProjectID, OfficeID and VehicleID the following:
Sum of KM Traveled
Cost per Project
The SQL View of my query is as follows:
Code:
SELECT LogBook.ProjectID, LogBook.OfficeID, LogBook.VehicleID, Sum([KMAfterTravel]-[KMBeforeTravel]) AS [KM Traveled], Sum(([KMAfterTravel]-[KMBeforeTravel])*[Unit Cost]) AS [Cost per Project]
FROM VHCostPerKM INNER JOIN LogBook ON (VHCostPerKM.OfficeID = LogBook.OfficeID) AND (VHCostPerKM.VehicleID = LogBook.VehicleID)
WHERE (((LogBook.DateOfTravel) Between [Forms]![rpt2Select]![cboFromDate] And [Forms]![rpt2Select]![cboToDate]))
GROUP BY LogBook.ProjectID, LogBook.OfficeID, LogBook.VehicleID;
I also need to show description in place of ProjectID, OfficeID and VehicleID.
I added Project table and replaced ProjectID with Description field of Project Table. This worked fine and at this stage, SQL View was as follows:
Code:
SELECT Project.Description AS Project, LogBook.OfficeID, LogBook.VehicleID, Sum([KMAfterTravel]-[KMBeforeTravel]) AS [KM Traveled], Sum(([KMAfterTravel]-[KMBeforeTravel])*[Unit Cost]) AS [Cost per Project]
FROM (VHCostPerKM INNER JOIN LogBook ON (VHCostPerKM.OfficeID = LogBook.OfficeID) AND (VHCostPerKM.VehicleID = LogBook.VehicleID)) INNER JOIN Project ON LogBook.ProjectID = Project.ProjectID
WHERE (((LogBook.DateOfTravel) Between [Forms]![rpt2Select]![cboFromDate] And [Forms]![rpt2Select]![cboToDate]))
GROUP BY Project.Description, LogBook.OfficeID, LogBook.VehicleID;
Then I added Office table and replaced OfficeID with Description field of Office Table. When I executed the query this time, Office column appeared blank. At this stage, SQL View was as follows:
Code:
SELECT Project.Description AS Project, Office.Description AS Office, LogBook.VehicleID, Sum([KMAfterTravel]-[KMBeforeTravel]) AS [KM Traveled], Sum(([KMAfterTravel]-[KMBeforeTravel])*[Unit Cost]) AS [Cost per Project]
FROM ((VHCostPerKM INNER JOIN LogBook ON (VHCostPerKM.OfficeID = LogBook.OfficeID) AND (VHCostPerKM.VehicleID = LogBook.VehicleID)) INNER JOIN Project ON LogBook.ProjectID = Project.ProjectID) INNER JOIN Office ON LogBook.OfficeID = Office.OfficeID
WHERE (((LogBook.DateOfTravel) Between [Forms]![rpt2Select]![cboFromDate] And [Forms]![rpt2Select]![cboToDate]))
GROUP BY Project.Description, Office.Description, LogBook.VehicleID;