Hi,
Here's my problem:
Need to run weekly reports every Monday or Tuesday. However, regardless of which day we run the report on, it has to calculate sums of sales figures for the previous week starting on the previous SUNDAY.
So if we run the report today, June 27th, I need the sales figures from June 18th at midnight through June 25th at midnight. (I think that's exactly one week)
So, it's not enough to do GETDATE() -7. Currently, we are using DATEPART(wk, 'date')-1, which takes the current week number (this week is week 26 for the calendar year), minus one is 25, or the previous week starting on Sunday.
This works fine until you get to January 1, 2007. Then you're back to week 1. If you subtract 1 from week 1, you get zero, not week 53 (the last week of December - which in this case will only consist of one day - Dec. 31st).
So, even IF week one minus one = week 53, it still doesn't work, because week 53 only has one day... and we need the entire week for the sales figures... that is, Dec 31 to January 6.
See the problem?? Don't know how to write this at all!
Need help, please.
Thank you
Here's my problem:
Need to run weekly reports every Monday or Tuesday. However, regardless of which day we run the report on, it has to calculate sums of sales figures for the previous week starting on the previous SUNDAY.
So if we run the report today, June 27th, I need the sales figures from June 18th at midnight through June 25th at midnight. (I think that's exactly one week)
So, it's not enough to do GETDATE() -7. Currently, we are using DATEPART(wk, 'date')-1, which takes the current week number (this week is week 26 for the calendar year), minus one is 25, or the previous week starting on Sunday.
This works fine until you get to January 1, 2007. Then you're back to week 1. If you subtract 1 from week 1, you get zero, not week 53 (the last week of December - which in this case will only consist of one day - Dec. 31st).
So, even IF week one minus one = week 53, it still doesn't work, because week 53 only has one day... and we need the entire week for the sales figures... that is, Dec 31 to January 6.
See the problem?? Don't know how to write this at all!
Need help, please.
Thank you