New to Access - Quarterly Query Help

Danreed87

New member
Local time
Yesterday, 16:47
Joined
Jan 15, 2014
Messages
1
Hi,

I have a table where I record attendance. In the table they select the type of training in via a check box "Training, Drill or Other". I created a query to show how many times someone has attended the Drills in each quarter (counts the check box). I am wanting to be able to specify which year is displayed as atm it is showing all te quarters for years. Can anyone help? The SQL is below.

From this I have a report where it displays the data and have conditional formatted it so that if they have not attended more than 4 times in one quarter the "cell" turns red - the only problem is is that some of the cells have no data in it. How can I get the query to display 0 if there is no data?

QUERY SQL:
TRANSFORM Sum(Abs([ATTENDANCE 2011].DRILL)) AS SumOfDRILL
SELECT [MEMBERS LIST].[NUMBER/NAME], Sum(Abs(Nz([ATTENDANCE 2011].DRILL,0))) AS [Total Of DRILL]
FROM [MEMBERS LIST] INNER JOIN [ATTENDANCE 2011] ON [MEMBERS LIST].ID = [ATTENDANCE 2011].ATTENDED.Value
GROUP BY [MEMBERS LIST].[NUMBER/NAME]
PIVOT "Qtr " & Format([DATE],"yyyy/q");


Cheers

Dan
 
1) use code tags to post sql or any code on any forum (the # button on the post menu)
2) Post your code/sql readable
3) dont use date as a column name it is a reserved word that can cause you trouble
4) you shouldnt use dates or years in table names, as you probably will have data for more than one year
5) Dont use spaces or special chars in any of your columns or table names.
Code:
TRANSFORM Sum(Abs([ATTENDANCE 2011].DRILL)) AS SumOfDRILL
SELECT [MEMBERS LIST].[NUMBER/NAME], Sum(Abs(Nz([ATTENDANCE 2011].DRILL,0))) AS [Total Of DRILL]
FROM [MEMBERS LIST] 
INNER JOIN [ATTENDANCE 2011] ON [MEMBERS LIST].ID = [ATTENDANCE 2011].ATTENDED.Value
GROUP BY [MEMBERS LIST].[NUMBER/NAME]
PIVOT "Qtr " & Format([DATE],"yyyy/q");

What exactly do you mean "all the quarters for years" you mean there is data there for the past x years and you want to only show past 2 years or something?
If so simply add some having clause to the query, something like:
Code:
TRANSFORM Sum(Abs([ATTENDANCE 2011].DRILL)) AS SumOfDRILL
SELECT [MEMBERS LIST].[NUMBER/NAME], Sum(Abs(Nz([ATTENDANCE 2011].DRILL,0))) AS [Total Of DRILL]
FROM [MEMBERS LIST] 
INNER JOIN [ATTENDANCE 2011] ON [MEMBERS LIST].ID = [ATTENDANCE 2011].ATTENDED.Value
GROUP BY [MEMBERS LIST].[NUMBER/NAME]
Having [date] > Datevalue(Year(date())-1,1,1) 
PIVOT "Qtr " & Format([DATE],"yyyy/q");
This will only show quarters from 2013/01/01 and onwards.

No data/blank cells can be prevented if you really want to, but why not simply adjust your formatting to accomidate "no data" (NULL)
 

Users who are viewing this thread

Back
Top Bottom