Hi,

I need a view with weeknumbers according to ISO. This means 1-1-2006 is week 53.
Now I created a function:

[MS SQL] CREATE FUNCTION dbo.WOY
( @Date DATETIME )
RETURNS SMALLINT
AS
BEGIN
DECLARE @WEEK SMALLINT
IF DATEPART(dw, CAST('1-1-' + CAST(DATEPART(YYYY, @Date) AS VARCHAR) AS DATETIME)) > 4
IF DATEPART(ww, @Date) = 1
SET @WEEK = 53
ELSE SET @WEEK = DATEPART(ww, @Date) -1
ELSE SET @WEEK = DATEPART(ww, @Date)
RETURN ( @WEEK )
END[/MS SQL]

In a view I added a column WOY(Date)

Now I need somehow set the datefirst to 1 but how can I do that?

Anyone?

I tried your function:

PRINT dbo.WOY(01/01/2006)

I got = 1
What do you mean set the datefirst to 1.
Are you implying that 1-1-2006 = week 1??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.