I have the DateFirst set to 7. Now when I run the following SQL, it returns week 1:
SET DateFirst 7
SELECT DATEPART(wk, '1/1/2011') as WeekNumber
I am not sure why this is returning week 1 though, if my start day is set to 7. According to me week 1 should start on the 1/2/2011, which is a Sunday. How can I correct this?
From http://msdn.microsoft.com/en-us/library/ms174420%28v=sql.90%29.aspx
So: because it is defined as such.
Edit: You can fix this within SQL-SERVER. Use something like this:
What this code does, is use the current day of the year and the weekday to calculate which day was the first Sunday of the year, then subtracts that day from the current date, giving you a virtual date in which the year started on a Sunday and then takes the week number of that date, which should be equal to the week number according to your definition.