Skip to main content
Inspiring
July 31, 2008
Question

Weeks Numbers

  • July 31, 2008
  • 2 replies
  • 531 views
Hello All

Any ideas on the best way to work out what month a particular week is in.

Im getting my data returned from the SQL server groupped by 'datepart' see below

So im getting a list of orders totaled by week.

the week is the week number i.e. wk31 wk32 wk33
How can I determin what month wk31 falls in for reporting I want to display the month with the apropriat weeks below it.

Kind Regards Guy
and thanks for any help in advance.


************ SQL for datepart grouping *****************
This topic has been closed for replies.

2 replies

Inspiring
July 31, 2008
When I wonder about stuff like that, I code it and try it.
HagsterAuthor
Inspiring
August 1, 2008
I know :), thought it was a little cheeky asking.

Any how thanks for the replys all working and done now.

Regards
Inspiring
July 31, 2008
The simplest way is to select the datepart that gives you the month as part of your query. Before doing so, decide what to do about weeks that have two months, this week for example.
HagsterAuthor
Inspiring
July 31, 2008
Thanks Dan, obviously its such a simple solution, why do things like this just evade me :)

Any way being a little lazy here I have set up my SQL to do as you surgested, but have a question with weeks that have two months as this one, how does the MS Server denote which month to put the week into?
is it the month that the week starts in?

I will go work it out tomorrow just wondered if you new of top of your head.

***** new select below********************

SELECT MONTH(planned.planddate) AS planmonth, DATEPART(ww, PLANNED.planddate) AS planweek,