Re: Month date offset query
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Mon, 7 Jul 2008 12:16:26 -0400
chemicals wrote:
I have a table that contains:
Project, Phase, StartDate, Month1, Month2, Month3,...Month48
Ecah Month column contains the number of hours spent in that month on
the project. The Month columns are not dates.
Does "Month1" mean "Jan2008" or "FirstMonthOfProjectExistence"?
I am trying to query the projects so that I can align all of the
columns of hours based on the current month.
For example is the data was:
Proj A, Build, 2/08, 5,10,15,20,...240
Proj B, Build, 5/08, 1,3,5,7,...97
Proj C, Build,11/07, 2,4,6,8,...96
The output would be:
Proj A, Build, 2/08, 30,35,40,45,...240 (skips 1st 5 months)
Proj B, Build, 5/08, 5,7,9,11,...97 (skips 1st 2 months)
Proj C, Build,11/07, 20,22,24,26,...96 (skips 1st 9 months)
I am having trouble getting my hands around this...
Thanks
Outside of the discussion about the design, I'm having a little trouble
understanding the requirements. Let's see if I have it straight:
"Month1" does mean "FirstMonthOfProjectExistence", correct? So Month1 of
ProjA contains data for Feb2008 of ProjA, and Month1 of ProjB contains data
for May2008? ... yes, it is now making sense ... for starters, you need to
relate the MonthX columns to actual Date/Time values.
Let's assume the StartDate is an actual Date/Time column (if it isn't you
will need to add the necessary step to convert the data in that column to
Date/Time to what I am proposing). At the same time, you will need to
normalize the data with a union query:
Select Project, Phase, StartDate,
DateSerial(year(StartDate),month(startdate),1) As ReportingMonth
[Month1] As HoursUsed From TableName
Union All
Select Project, Phase, StartDate,
DateSerial(year(StartDate),month(startdate)+1,1) As ReportingMonth
[Month2] As HoursUsed From TableName
Union All
Select Project, Phase, StartDate,
DateSerial(year(StartDate),month(startdate)+2,1) As ReportingMonth
[Month3] As HoursUsed From TableName
....
Union All
Select Project, Phase, StartDate,
DateSerial(year(StartDate),month(startdate)+47,1) As ReportingMonth
[Month48] As HoursUsed From TableName
Save the above as NormalizedData (or whatever you like) and then, to select
the data, it's simply a matter of:
Select Project, Phase, StartDate,ReportingMonth,HoursUsed
From NormalizedDataWHERE ReportingMonth >= DateSerial(Year(Date),Month(Date),1)
Save that query as CurrentMonthHours (or whatever name you prefer), and then
use it as the source "table" for the crosstab query wizard.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- References:
- Month date offset query
- From: chemicals
- Month date offset query
- Prev by Date: RE: Month date offset query
- Next by Date: Re: Limit Rows returned in a query
- Previous by thread: Re: Month date offset query
- Next by thread: Re: update blank fields
- Index(es):
Relevant Pages
|