P
P.McFarlane
I have been trying to create a query that shows some totals and stats (along
with some other stuff) and have reached a dead end. I don't even know if is
possible.
I have three tables; the first (called QAK1Data) holds project information.
Each record is data belonging to a unique JobNo. The second (called
BillingData) contains records of the day to day activity of a project. A
particular project may have none or many records. The third (called
InvoiceData) contains records of invoices for a project. A particular
project may have none or several records.
The following SQL statement almost works. Returned records are correct
EXCEPT when there is more than one InvoiceData record for a project. If
there are two InvoiceData records then the Costs and Charges records are
doubled and the Invoices record is halved. Any help in resolving this would
be appreciated.
SELECT QAK1Data.JobNo, QAK1Data.QuoteOnly, QAK1Data.OrderNo,
QAK1Data.OrderValue, QAK1Data.Desc, QAK1Data.Client, QAK1Data.DateRecvd,
QAK1Data.ProjectType, QAK1Data.ClientType, QAK1Data.FeeRange,
QAK1Data.ProjectManager, QAK1Data.InstructionSource, QAK1Data.Closed,
QAK1Data.ClosedDate, QAK1Data.BadDebt, Sum(BillingData.ThisCost) AS Costs,
Sum(BillingData.TotalCharge) AS Charges,
Sum([InvoiceData]![TotalCharge])/Count([BillingData]![JobNo]) AS Invoices,
(IIf([Invoices]=0,0,([invoices]/[Charges])*100)) AS Recovered,
IIf(Val([OrderValue])=0,'',[Charges]-[OrderValue]) AS QuoteDiff
FROM (InvoiceData RIGHT JOIN QAK1Data ON InvoiceData.JobNo = QAK1Data.JobNo)
LEFT JOIN BillingData ON QAK1Data.JobNo = BillingData.JobNo
GROUP BY QAK1Data.JobNo, QAK1Data.QuoteOnly, QAK1Data.OrderNo,
QAK1Data.OrderValue, QAK1Data.Desc, QAK1Data.Client, QAK1Data.DateRecvd,
QAK1Data.ProjectType, QAK1Data.ClientType, QAK1Data.FeeRange,
QAK1Data.ProjectManager, QAK1Data.InstructionSource, QAK1Data.Closed,
QAK1Data.ClosedDate, QAK1Data.BadDebt
HAVING (((QAK1Data.DateRecvd) Between DateValue('1/07/2008') And
DateValue('31/07/2008')))
ORDER BY QAK1Data.JobNo;
with some other stuff) and have reached a dead end. I don't even know if is
possible.
I have three tables; the first (called QAK1Data) holds project information.
Each record is data belonging to a unique JobNo. The second (called
BillingData) contains records of the day to day activity of a project. A
particular project may have none or many records. The third (called
InvoiceData) contains records of invoices for a project. A particular
project may have none or several records.
The following SQL statement almost works. Returned records are correct
EXCEPT when there is more than one InvoiceData record for a project. If
there are two InvoiceData records then the Costs and Charges records are
doubled and the Invoices record is halved. Any help in resolving this would
be appreciated.
SELECT QAK1Data.JobNo, QAK1Data.QuoteOnly, QAK1Data.OrderNo,
QAK1Data.OrderValue, QAK1Data.Desc, QAK1Data.Client, QAK1Data.DateRecvd,
QAK1Data.ProjectType, QAK1Data.ClientType, QAK1Data.FeeRange,
QAK1Data.ProjectManager, QAK1Data.InstructionSource, QAK1Data.Closed,
QAK1Data.ClosedDate, QAK1Data.BadDebt, Sum(BillingData.ThisCost) AS Costs,
Sum(BillingData.TotalCharge) AS Charges,
Sum([InvoiceData]![TotalCharge])/Count([BillingData]![JobNo]) AS Invoices,
(IIf([Invoices]=0,0,([invoices]/[Charges])*100)) AS Recovered,
IIf(Val([OrderValue])=0,'',[Charges]-[OrderValue]) AS QuoteDiff
FROM (InvoiceData RIGHT JOIN QAK1Data ON InvoiceData.JobNo = QAK1Data.JobNo)
LEFT JOIN BillingData ON QAK1Data.JobNo = BillingData.JobNo
GROUP BY QAK1Data.JobNo, QAK1Data.QuoteOnly, QAK1Data.OrderNo,
QAK1Data.OrderValue, QAK1Data.Desc, QAK1Data.Client, QAK1Data.DateRecvd,
QAK1Data.ProjectType, QAK1Data.ClientType, QAK1Data.FeeRange,
QAK1Data.ProjectManager, QAK1Data.InstructionSource, QAK1Data.Closed,
QAK1Data.ClosedDate, QAK1Data.BadDebt
HAVING (((QAK1Data.DateRecvd) Between DateValue('1/07/2008') And
DateValue('31/07/2008')))
ORDER BY QAK1Data.JobNo;