Crystal v10
SQL Server 2005
Hello,
I have a Monthly Client Hours Report I am working on. It's basically a manual crosstab. A SP on the db fires and populates a temp table with the data my report needs. The data use Fiscal Periods (12) and Transaction Dates. Example would be 200610 and 10/13/2006. I need to plug the hours an employee works into buckets on the report that correspond to the months. The months are listed across the top from Jan-Dec with a Total at the end. Hours can be listed in chunks such that there are multiple Detail records possible for an employee on a given date. Hours are posted to Fiscal Period but may not necessarily belong in that period. If it wasn't for the specific way the customer wants the hours buckets populated this would be a no-brainer. Rather than modify the program that the employees use to enter hours they want to control the buckets from the report based on the following rules:
If the hours are posted to Fiscal Period 200610 and the Transaction Date is less than the last day of the month those hours go in Oct.
If the hours are posted to Fiscal Period 200610 and the month of the Transaction Date is greater than the month of the Fiscal Period (ex. 11/01/2006) those hours belong in Nov.
If the two are equal than the hours go in whatever month they are.
Ex.
200610 10/02/2006 Oct.
200611 10/03/2006 Nov.
200610 11/03/2006 Nov.
That works, although it's ugly, until I try to seperate across years like 200612 and 01/03/2007. So then I started to try this:
but got lost in my head somewhere.
So to net it all out I need help with a formula or combination of formulas that will assign hours to monthly buckets following the above stated rules and breaking across years correctly. Year is defined as the year part of the Fiscal Period and I am also grouping on Year.
I am happy to add any additional information I may have left out, just ask.
TIA for the help.
SQL Server 2005
Hello,
I have a Monthly Client Hours Report I am working on. It's basically a manual crosstab. A SP on the db fires and populates a temp table with the data my report needs. The data use Fiscal Periods (12) and Transaction Dates. Example would be 200610 and 10/13/2006. I need to plug the hours an employee works into buckets on the report that correspond to the months. The months are listed across the top from Jan-Dec with a Total at the end. Hours can be listed in chunks such that there are multiple Detail records possible for an employee on a given date. Hours are posted to Fiscal Period but may not necessarily belong in that period. If it wasn't for the specific way the customer wants the hours buckets populated this would be a no-brainer. Rather than modify the program that the employees use to enter hours they want to control the buckets from the report based on the following rules:
If the hours are posted to Fiscal Period 200610 and the Transaction Date is less than the last day of the month those hours go in Oct.
If the hours are posted to Fiscal Period 200610 and the month of the Transaction Date is greater than the month of the Fiscal Period (ex. 11/01/2006) those hours belong in Nov.
If the two are equal than the hours go in whatever month they are.
Ex.
200610 10/02/2006 Oct.
200611 10/03/2006 Nov.
200610 11/03/2006 Nov.
Code:
whileprintingrecords;
numbervar m10;
numbervar m11;
numbervar m12;
numbervar m1;
numbervar m2;
numbervar m3;
numbervar m4;
numbervar m5;
numbervar m6;
numbervar m7;
numbervar m8;
numbervar m9;
if {xwrk_Hours.FNMonth} = 10
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m10 := m10 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 10 and {xwrk_Hours.FNMonth} = 11
then m11 := m11 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 11
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m11 := m11 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 11 and {xwrk_Hours.FNMonth} = 12
then m12 := m12 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 12
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m12 := m12 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 12 and {xwrk_Hours.FNMonth} = 1
then m1 := m1 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 1
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m1 := m1 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 1 and {xwrk_Hours.FNMonth} = 2
then m2 := m2 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 2
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m2 := m2 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 2 and {xwrk_Hours.FNMonth} = 3
then m3 := m3 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 3
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m3 := m3 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 3 and {xwrk_Hours.FNMonth} = 4
then m4 := m4 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 4
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m4 := m4 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 4 and {xwrk_Hours.FNMonth} = 5
then m5 := m5 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 5
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m5 := m5 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 5 and {xwrk_Hours.FNMonth} = 6
then m6 := m6 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 6
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m6 := m6 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 6 and {xwrk_Hours.FNMonth} = 7
then m7 := m7 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 7
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m7 := m7 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 7 and {xwrk_Hours.FNMonth} = 8
then m8 := m8 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 8
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m8 := m8 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 8 and {xwrk_Hours.FNMonth} = 9
then m9 := m9 + {xwrk_Hours.Hours}
else
if {xwrk_Hours.FNMonth} = 9
and {xwrk_Hours.Date_Entered} <= {@LastDayofMonth}
then m9 := m9 + {xwrk_Hours.Hours}
else if Month({xwrk_Hours.Date_Entered}) = 9 and {xwrk_Hours.FNMonth} = 10
then m10 := m10 + {xwrk_Hours.Hours}
That works, although it's ugly, until I try to seperate across years like 200612 and 01/03/2007. So then I started to try this:
Code:
if {xwrk_Hours.FNMonth} = Month({xwrk_Hours.Date_Entered})
then VMonth = 1
else
if {xwrk_Hours.FNMonth} > Month({xwrk_Hours.Date_Entered})
then VMonth = 2
else
if {xwrk_Hours.FNMonth} < Month({xwrk_Hours.Date_Entered})
then VMonth = 3
if VMonth = 1
then {xwrk_Hours.Hours}
else
if VMonth = 2
then {xwrk_Hours.Hours}
else
So to net it all out I need help with a formula or combination of formulas that will assign hours to monthly buckets following the above stated rules and breaking across years correctly. Year is defined as the year part of the Fiscal Period and I am also grouping on Year.
I am happy to add any additional information I may have left out, just ask.
TIA for the help.