C
cquinn
I am slightly new at access. I have created two queries that are
finding and summing calculations from the same field on the same table.
So it is the same information, two different ways. Then i am combining
these two queries into a third query that is just a query to gather all
information to shoot into a report for my end of the month billings.
The queries are using data from a form that i use. That is where my
StartDate, EndDate, and JobCode are located. The third query seems to
be adding the right records, but then multiplying by the total amount
of records found in the table. Here is my code. Any help would be
greatly appreciated.
SELECT DISTINCTROW [MASTER BID TABLE].CostCode, [MASTER BID
TABLE].Description, [MASTER BID TABLE].TotalQuantity, [MASTER BID
TABLE].UnitsOfMeasure, [MASTER BID TABLE].UnitCost,
Sum([TotalQuantity]*[UnitCost]) AS TotalAmtBid, Sum(IIf(IsNull([query-
THIS BILLING QUANTITY]!Qty),0,[query- THIS BILLING QUANTITY]!Qty)) AS
QtyThisBill, Sum([query- THIS BILLING QUANTITY]!Qty*[UnitCost]) AS
TotalAmtThisBill, Sum(IIf(IsNull([query- PREV BILLED
QTY]!Qty),0,[query- PREV BILLED QTY]!Qty)) AS QtyPrevBill,
Sum([UnitCost]*[query- PREV BILLED QTY]!Qty) AS TotalAmtPrevBilled,
[QtyPrevBill]+[QtyThisBill] AS TotalQtyTD, Sum(((IIf(IsNull([query-
THIS BILLING QUANTITY]!Qty),0,[query- THIS BILLING
QUANTITY]!Qty))+(IIf(IsNull([query- PREV BILLED QTY]!Qty),0,[query-
PREV BILLED QTY]!Qty)))*[UnitCost]) AS TotalAmtTD,
Format([TotalQtyTD]/[TotalQuantity],"Percent") AS PercentComplete, [JOB
SITE].Description, [JOB SITE].Address1, [JOB SITE].Address2, [JOB
SITE].Owner, [JOB SITE].OwnerAddress1, [JOB SITE].OwnerAddress2, [JOB
SITE].OwnerPhone, Forms![form- MONTHLY BILLING]!StartDate AS StartDate,
Forms![form- MONTHLY BILLING]!EndDate AS EndDate, [JOB
SITE].ProjectManager, [MASTER BID TABLE].JobCode, [JOB
SITE].ProjectManagerPhone
FROM ([query- PREV BILLED QTY] RIGHT JOIN ([query- THIS BILLING
QUANTITY] RIGHT JOIN [MASTER BID TABLE] ON [query- THIS BILLING
QUANTITY].CostCode = [MASTER BID TABLE].CostCode) ON [query- PREV
BILLED QTY].CostCode = [MASTER BID TABLE].CostCode) INNER JOIN [JOB
SITE] ON [MASTER BID TABLE].JobCode = [JOB SITE].JobCode
GROUP BY [MASTER BID TABLE].CostCode, [MASTER BID TABLE].Description,
[MASTER BID TABLE].TotalQuantity, [MASTER BID TABLE].UnitsOfMeasure,
[MASTER BID TABLE].UnitCost, [JOB SITE].Description, [JOB
SITE].Address1, [JOB SITE].Address2, [JOB SITE].Owner, [JOB
SITE].OwnerAddress1, [JOB SITE].OwnerAddress2, [JOB SITE].OwnerPhone,
Forms![form- MONTHLY BILLING]!StartDate, Forms![form- MONTHLY
BILLING]!EndDate, [JOB SITE].ProjectManager, [MASTER BID
TABLE].JobCode, [JOB SITE].ProjectManagerPhone
HAVING ((([MASTER BID TABLE].JobCode)=[Forms]![form- MONTHLY
BILLING]![Combo6]))
ORDER BY [MASTER BID TABLE].CostCode;
finding and summing calculations from the same field on the same table.
So it is the same information, two different ways. Then i am combining
these two queries into a third query that is just a query to gather all
information to shoot into a report for my end of the month billings.
The queries are using data from a form that i use. That is where my
StartDate, EndDate, and JobCode are located. The third query seems to
be adding the right records, but then multiplying by the total amount
of records found in the table. Here is my code. Any help would be
greatly appreciated.
SELECT DISTINCTROW [MASTER BID TABLE].CostCode, [MASTER BID
TABLE].Description, [MASTER BID TABLE].TotalQuantity, [MASTER BID
TABLE].UnitsOfMeasure, [MASTER BID TABLE].UnitCost,
Sum([TotalQuantity]*[UnitCost]) AS TotalAmtBid, Sum(IIf(IsNull([query-
THIS BILLING QUANTITY]!Qty),0,[query- THIS BILLING QUANTITY]!Qty)) AS
QtyThisBill, Sum([query- THIS BILLING QUANTITY]!Qty*[UnitCost]) AS
TotalAmtThisBill, Sum(IIf(IsNull([query- PREV BILLED
QTY]!Qty),0,[query- PREV BILLED QTY]!Qty)) AS QtyPrevBill,
Sum([UnitCost]*[query- PREV BILLED QTY]!Qty) AS TotalAmtPrevBilled,
[QtyPrevBill]+[QtyThisBill] AS TotalQtyTD, Sum(((IIf(IsNull([query-
THIS BILLING QUANTITY]!Qty),0,[query- THIS BILLING
QUANTITY]!Qty))+(IIf(IsNull([query- PREV BILLED QTY]!Qty),0,[query-
PREV BILLED QTY]!Qty)))*[UnitCost]) AS TotalAmtTD,
Format([TotalQtyTD]/[TotalQuantity],"Percent") AS PercentComplete, [JOB
SITE].Description, [JOB SITE].Address1, [JOB SITE].Address2, [JOB
SITE].Owner, [JOB SITE].OwnerAddress1, [JOB SITE].OwnerAddress2, [JOB
SITE].OwnerPhone, Forms![form- MONTHLY BILLING]!StartDate AS StartDate,
Forms![form- MONTHLY BILLING]!EndDate AS EndDate, [JOB
SITE].ProjectManager, [MASTER BID TABLE].JobCode, [JOB
SITE].ProjectManagerPhone
FROM ([query- PREV BILLED QTY] RIGHT JOIN ([query- THIS BILLING
QUANTITY] RIGHT JOIN [MASTER BID TABLE] ON [query- THIS BILLING
QUANTITY].CostCode = [MASTER BID TABLE].CostCode) ON [query- PREV
BILLED QTY].CostCode = [MASTER BID TABLE].CostCode) INNER JOIN [JOB
SITE] ON [MASTER BID TABLE].JobCode = [JOB SITE].JobCode
GROUP BY [MASTER BID TABLE].CostCode, [MASTER BID TABLE].Description,
[MASTER BID TABLE].TotalQuantity, [MASTER BID TABLE].UnitsOfMeasure,
[MASTER BID TABLE].UnitCost, [JOB SITE].Description, [JOB
SITE].Address1, [JOB SITE].Address2, [JOB SITE].Owner, [JOB
SITE].OwnerAddress1, [JOB SITE].OwnerAddress2, [JOB SITE].OwnerPhone,
Forms![form- MONTHLY BILLING]!StartDate, Forms![form- MONTHLY
BILLING]!EndDate, [JOB SITE].ProjectManager, [MASTER BID
TABLE].JobCode, [JOB SITE].ProjectManagerPhone
HAVING ((([MASTER BID TABLE].JobCode)=[Forms]![form- MONTHLY
BILLING]![Combo6]))
ORDER BY [MASTER BID TABLE].CostCode;