Hello raskew. I don't know how clear this will be to you but I'll be happy to try and explain. I'll try and keep this short.
These are the columns I've been talking about in table [Daily Record Sheet] (a sheet filled out by work gangs and recorded in the database every day - or so). This table is at the top of the database design.
OpCode1 OpCode2 OpCode3 OpCode4 OpCode5
200 220 220 201 0
200 220 220 201 240
220 240 220 0 0
Here is an edited excerpt from the table [Daily Labour] which has a 1 to many relationship with [Day Record Sheet] above.
Lab Desc Op Code
Mobile Crane Driver > 6 ton 1
Building Trade Crafstman 1
Building Trade Crafstman 1
Mobile Crane Driver > 6 ton 2
Building Trade Crafstman 2
....
This is the first query I use (saved as LabourCostsAggregate):
SELECT DISTINCTROW Sum(([Hrs@1:0]*[Ratex1:0])+([Hrs@1:5]*[Ratex1:5])+([Hrs@2:0]*[Ratex2:0])) AS [Labour Costs], [Daily Labour].[Op Code] AS Code, [Daily Labour].[Lab Desc] AS LabDesc, [Daily Record Sheet].SheetNum, [Daily Record Sheet].OpCode1 AS OC1, [Daily Record Sheet].OpCode2 AS OC2, [Daily Record Sheet].OpCode3 AS OC3, [Daily Record Sheet].OpCode4 AS OC4, [Daily Record Sheet].OpCode5 AS OC5
FROM [Daily Record Sheet], [Daily Labour]
WHERE ((([Daily Record Sheet].SheetID)=[Daily Labour].[SheetID]))
GROUP BY [Daily Labour].[Op Code], [Daily Labour].[Lab Desc], [Daily Record Sheet].SheetNum, [Daily Record Sheet].OpCode1, [Daily Record Sheet].OpCode2, [Daily Record Sheet].OpCode3, [Daily Record Sheet].OpCode4, [Daily Record Sheet].OpCode5, [Daily Record Sheet].SheetNum
ORDER BY [Daily Record Sheet].SheetNum;
Then for each column I use query LabourCostsOpCode1 ... 5
SELECT DISTINCTROW LabourCostsAggregate.[Labour Costs], LabourCostsAggregate.Code, LabourCostsAggregate.LabDesc, [Daily Record Sheet].SheetNum AS SheetNum, LabourCostsAggregate.OC1
FROM LabourCostsAggregate
WHERE (((LabourCostsAggregate.Code)=1));
Then I UNION them together in LabourCostsOpCodeUnion:
TABLE LabourCostsOpCode1
UNION
TABLE LabourCostsOpCode2
UNION
TABLE LabourCostsOpCode3
UNION
TABLE LabourCostsOpCode4
UNION TABLE LabourCostsOpCode5;
Then I finally arrive at the point where I can get at the data I want for a report with this query
SELECT Sum(LabourCostsOpCodeUnion.[Labour Costs]) AS Costs, LabourCostsOpCodeUnion.OC1, LabourCostsOpCodeUnion.LabDesc
FROM LabourCostsOpCodeUnion
GROUP BY LabourCostsOpCodeUnion.OC1, LabourCostsOpCodeUnion.LabDesc;
And this is how the final datasheet looks:
Costs OC1 LabDesc
£1,728.00 0 Building Trade Crafstman
£1,344.00 0 Construction Supervisor
£1,555.20 220 Labourer
£2,355.60 220 Mechanical Excavator Driver
£576.00 220 Mobile Crane Driver > 6 ton
£1,113.60 230 Mobile Crane Driver > 6 ton
£288.00 240 Labourer
.............
etc.
Still here??? I admire your patience. Sorry if I've gone into too much detail but it's easier for *me* that way.
Not very elegant but it does do the job. Of course, as Pat pointed out better design would have made all this unnecessary.
Cheers,
Peter