Here is the query I am using to get this done.
I have a date field in my table in format m/dd/yyyy hh:mm:ss AM.
Depending the date selected by user, I need to display the corresponding month's data like previous 4 weeks
If the month begining falls in weekday other than Monday, It should give the whole month begining week's data
For Ex: Aug 01 2008 is Friday.
When user runs report he/she see data for the whole Aug 2008 and also the week ending Aug 01 2008 which includes 07/28, 07/29,7/30,7/31.
On the whole one should see the data asof every weekend for that particular month including month begining falls in previous month's weekend
I tried a query with switch statement but it is not working with Business Objects.
Please advise
This is my urgent requirement
Here is the query I am using at Acces which is working fine.But Dateadd function is giving me error when I use this in Business Objects
Can anybody help me the other workaround for this ?/
SELECT X.week AS week, sum(X.TotalCalls) AS [sum], X.vgroup AS groupname
FROM [select tbl_ATTLog_Master.vDate, tbl_ATTLog_Master.TotalCalls, tbl_ATTLog_Master.vgroup,
switch(tbl_ATTLog_Master.vDate<=
dateadd("d",6,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
and
tbl_ATTLog_Master.vDate >=
dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)) , dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)),
tbl_ATTLog_Master.vDate>
dateadd("d",6,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
and
tbl_ATTLog_Master.vDate <=
dateadd("d",13,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
, dateadd("d",13,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1))),
tbl_ATTLog_Master.vDate>
dateadd("d",13,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
and
tbl_ATTLog_Master.vDate <=
dateadd("d",20,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
, dateadd("d",20,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1))) ,
tbl_ATTLog_Master.vDate>
dateadd("d",20,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
and
tbl_ATTLog_Master.vDate <=
dateadd("d",27,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
,dateadd("d",27,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1))) ,
tbl_ATTLog_Master.vDate>
dateadd("d",27,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
and
tbl_ATTLog_Master.vDate <=
dateadd("d",34,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
, dateadd("d",34,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
) as week
from
tbl_ATTLog_Master
where
tbl_ATTLog_Master.vDate >= dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()),
month(date()), 1)) and
tbl_ATTLog_Master.vDate <=
dateadd("d",34,dateadd("d",-weekday(DateSerial(year(date()), month(date()), 1)), DateSerial(year(date()), month(date()), 1)))
]. AS X
GROUP BY X.week, X.vgroup;