• Like I stated in my first post: It depends on the requirement.

    You cannot use DATEPART() if you need to get the week as per ISO specification.

    Furthermore, DATEPART(WEEK,somedate) will return different results based on the setting of DATEFIRST.

    Straight from BOL:

    The week (wk, ww) datepart reflects changes made to SET DATEFIRST. January 1 of any year defines the starting number for the week datepart, for example: DATEPART(wk, 'Jan 1, xxxx') = 1, where xxxx is any year.

    Here are a few examples. Please note, that none of the DATEPART() function does return the correct ISO week and neither are the results consistent.

    DECLARE @date DATETIME

    SET @date='20100102'--Saturday, January 1st, as per ISO definition week 53 of year 2009

    SET DATEFIRST 1

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 2

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 3

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 4

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 5

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 6

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo

    SET DATEFIRST 7

    SELECT @@DATEFIRST AS DATEFIRST,DATEPART(WEEK,@date) AS WeekNo



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]