inspectorgadjet
New member
- Local time
- Today, 17:25
- Joined
- Sep 24, 2004
- Messages
- 9
I am working on a project that requires a LOT of calculation, and I have managed to get to the end and have everything working. Or so I thought until yesterday afternoon.
I have a query, that calculates the average number of hours each person has spent in a specific situation per week. This works just great and returns the correct results. I then need to work out which Band they fall into based on number of hours. For example. Person A averaged 4 hours and will go into Band A, Person B averaged 12 hours and will go into Band B. I've also got this part of the query working. So far so good. The query outputs data similar to the following:
QueryA
Name AvgHours BandA BandB BandC BandD
PersonA 5 1 0 0 0
PersonB 12 0 1 0 0
PersonC 16 0 0 1 0
I've filled in the Band columns using an Iif function:
Iif(AvgHours BETWEEN 0 AND 6, 1, 0) and so on.
The database user cna then view a report which displays all of the data with checkboxes instead of 1s and 0s. This works out just great.
The next stage for me is to get the total number in each band and send it to another central database for reporting. This is where the problem comes in. I have created another query to calculate the totals.
QueryATotals
SELECT 1 AS Area,'2003/2004' AS Year, Sum(QueryA.BandA) AS BandATotal, Sum(QueryB.BandB) AS BandBTotal, Sum(QueryC.BandC) AS BandDTotal, Sum(QueryD.BandD) AS BandDTotal FROM QueryA
I have hardcoded an area number and year in for test purposes. The problem now seems to be that BandA returns a count of all the records in the query. So using my above example, it would return 3. BandB returns 0 when it should be a 1, and BandC returns a 1, which is correct.
I have tried using iif to calculate the right results, using a count in a subquery with a where clause, but nothing works. BandA always gets the total number of records, BandB is always 0, and BandC gets the right result. I'm stumped. Can anyone help me out?