Hello,
I have been tasked by my company to create a database to compare our actual costs on projects to what was budgeted for. Prior to this, I had never opened Access, and have had no internal guidance, so it has been an adventure to say the least.
We have 3 sets of data I've created a query to compare: The budget, the costs reported in the field, and the actual costs per our accounting system. Additionally, for each project, the costs are broken down into 45 different subcodes describing the classification of the work done.
I have built 3 queries, one for each data set, that sums all costs for a each subcode. Then I have another query that compares the sums for each subcode of each data set. That query works fine as long as there is data from each set for a given subcode. If there is no data for one of the three data sets, the query ignores that subcode entirely. I would prefer it to show a zero where there is no data in the comparison.
Here is my SQL code for the main query(All generated with the design view of Access. I have little understanding the coding):
SELECT Wells.WellCode, Wells.WellName, Prospects.[Prospect Name], Wells.[Frac Date], [Codes - Intangible].Sub, [Codes - Intangible].Description, AFEIntangSubCode.SumOfAFECost, WellEZIntangSubCode.SumOfWellEZCum, CostsIntangSubCode.[SumOfGross Amount], [SumOfGross Amount]-[SumOfAFECost] AS Overage, [Overage]/[SumOfAFECost] AS Percentage, Wells.Spacing
FROM (((Prospects INNER JOIN Wells ON Prospects.[Prospect Code] = Wells.Prospect) INNER JOIN AFEIntangSubCode ON Wells.WellCode = AFEIntangSubCode.WellCode) INNER JOIN WellEZIntangSubCode ON Wells.WellCode = WellEZIntangSubCode.WellCode) INNER JOIN (CostsIntangSubCode INNER JOIN [Codes - Intangible] ON CostsIntangSubCode.Sub = [Codes - Intangible].Sub) ON (AFEIntangSubCode.Sub = [Codes - Intangible].Sub) AND (WellEZIntangSubCode.Sub = [Codes - Intangible].Sub) AND (Wells.WellCode = CostsIntangSubCode.[Property #])
GROUP BY Wells.WellCode, Wells.WellName, Prospects.[Prospect Name], Wells.[Frac Date], [Codes - Intangible].Sub, [Codes - Intangible].Description, AFEIntangSubCode.SumOfAFECost, WellEZIntangSubCode.SumOfWellEZCum, CostsIntangSubCode.[SumOfGross Amount], Wells.Spacing, Prospects.[Prospect Code]
HAVING (((Wells.WellCode) Like IIf(IsNull([Forms]![Subcode Analysis]![WellCode]),"*",[Forms]![Subcode Analysis]![WellCode])) AND ((Prospects.[Prospect Name]) Like IIf(IsNull([Forms]![Subcode Analysis]![ProspectName]),"*",[Forms]![Subcode Analysis]![ProspectName])) AND ((Wells.[Frac Date]) Between [Forms]![Subcode Analysis]![StartDate] And [Forms]![Subcode Analysis]![EndDate]) AND (([Codes - Intangible].Sub) Like IIf(IsNull([Forms]![Subcode Analysis]![SubCode]),"*",[Forms]![Subcode Analysis]![SubCode])) AND ((Wells.Spacing) Like IIf(IsNull([Forms]![Subcode Analysis]![DSUSize]),"*",[Forms]![Subcode Analysis]![DSUSize])))
ORDER BY Wells.[Frac Date];
I think I can solve the problem by going through and entering zeros for each subcode that currently don't have costs, but I expect there's a much more elegant, and obvious solution.
Thanks for your help,
-Patrick