In MS SQL, January 1 of any year defines the starting number for the week. The DATEPART(wk, 'Jan 1, xxxx') always return 1. However, a lot of reports Week No is actually based on ISO 8601 standard, that is January 1 of any year can be Week 53/52 or Week 1. (http://www.merlyn.demon.co.uk/weekinfo.htm#IDC)
The Rule is as follows:
The first Week of a Year is Number 01, which is :-
*defined as being the week which contains the first Thursday of the Calendar year; which implies that it is also :-
*the first week which is mostly within the Calendar year,
*the week containing January 4th,
*the week starting with the Monday nearest to January 1st.
The conditions are mutually equivalent. See Markus Kuhn and R.H. van Gent, via datefmts.htm, for example.
The last Week of a Year, Number 52 or 53, therefore is :-
*the week which contains the last Thursday of the Calendar year;
*the last week which is mostly within the Calendar year;
*the week containing December 28th;
*the week ending with the Sunday nearest to December 31st.
Run the scripts below, and test
Declare @tDate Datetime
set @tDate =getdate()
select dbo.udf_DT_ISOWeekNum (@tDate)
A Normalization Primer
For most DBAs, normalization is an understood concept, a bread and butter bit of knowledge. However, it is not at all unusual to review a database design by a development group for an OLTP (OnLine Transaction Processing) environment and find that the schema chosen is anything but properly normalized. This article by Brian Kelley will give you the core knowledge to data model.
2003-01-13
18,613 reads