Hello,
I have to calculate a sum of deliveries since the beginning of the month. The point is that the first day of the "month" is NOT the 1st, but a day calculated as follows:
S M T W T F S| S M T W T F S|S M T W T F S|S M T W T F S
1 2 3 4 5 6 7| x 1 2 3 4 5 6|x x 1 2 3 4 5|x x x 1 2 3 4
In this case the month is starting either from the 1, or from the days of the previous month marked with "x".
S M T W T F S|S M T W T F S|S M T W T F S
x x x x 1 2 3| x x x x x 1 2|x x x x x x 1
In this cases the week in exam will go to the previous month, and our month will start from the 4th, the 3rd and the 2nd respectively.
Now, I have to write a query WHERE the date is between today and the beginning of the month. This date comes from a Form ("DateTo"), and have to perform a check (I guess, whether the month starts since the 5th day of the week or not).
I wrote that:
WHERE SU116.DATE = CASE WHEN DATEPART(dw,DATEADD(month, DATEDIFF(month, 0, [Forms]![Form1]![DateTo]), 0)) >= 5 THEN DateAdd("d",9-DATEPART(dw,[Forms]![Form1]![DateTo]),[Forms]![Form1]![DateTo]) ELSE DateAdd("d",0-DATEPART(dw,[Forms]![Form1]![DateTo])+1,[Forms]![Form1]![DateTo]) END
But it's not working ("missing operator").
Could you be so kind to give me a really appreciated help?
Thank you
I have to calculate a sum of deliveries since the beginning of the month. The point is that the first day of the "month" is NOT the 1st, but a day calculated as follows:
S M T W T F S| S M T W T F S|S M T W T F S|S M T W T F S
1 2 3 4 5 6 7| x 1 2 3 4 5 6|x x 1 2 3 4 5|x x x 1 2 3 4
In this case the month is starting either from the 1, or from the days of the previous month marked with "x".
S M T W T F S|S M T W T F S|S M T W T F S
x x x x 1 2 3| x x x x x 1 2|x x x x x x 1
In this cases the week in exam will go to the previous month, and our month will start from the 4th, the 3rd and the 2nd respectively.
Now, I have to write a query WHERE the date is between today and the beginning of the month. This date comes from a Form ("DateTo"), and have to perform a check (I guess, whether the month starts since the 5th day of the week or not).
I wrote that:
WHERE SU116.DATE = CASE WHEN DATEPART(dw,DATEADD(month, DATEDIFF(month, 0, [Forms]![Form1]![DateTo]), 0)) >= 5 THEN DateAdd("d",9-DATEPART(dw,[Forms]![Form1]![DateTo]),[Forms]![Form1]![DateTo]) ELSE DateAdd("d",0-DATEPART(dw,[Forms]![Form1]![DateTo])+1,[Forms]![Form1]![DateTo]) END
But it's not working ("missing operator").
Could you be so kind to give me a really appreciated help?
Thank you