Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping data by Month 1

Status
Not open for further replies.

Ryath

Technical User
Feb 24, 2002
84
GB
Hi all,

Got a quickey question for you all currently i have data that looks like this:-

Date Hours
1/5/99 21
2/5/99 41
18/5/99 15
21/8/99 77
31/8/99 4
etc etc

So as observed the hours can be varied from month to month, and some months...ie june and july in the example are missing. How can i group the data by month to give me a total per month, but also saying that june and july has 0 hours?

Thx all
Will [hammer]
 
I would attempt a cross tab query as follows:
[tt]
TRANSFORM IIf(SUM(Hours) Is Null,SUM(Hours),0)
SELECT Null
FROM YourTable
GROUP BY Null
PIVOT Month([Date]) IN (5,6,7,8)
[/tt]
The in clause makes certain that there is a column for each month June through August. I had to put the SELECT Null and GROUP BY Null clauses in to make access happy. These statements just result in an extra, useless field.
 
Thx, it works.... the dreaded but: is there a way to get it in column format so the date is in the column rather than a row? Will [hammer]
 
Unfortunately, I don't know of a way to do this and have the months June and July present unless either you have dates in the table, or you have a separate reference table that lists all the months in the year. For example, you could left join from a table as follows:
[tt]
tblMonth
--------
Month Text(10)
January
February
etc...
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top