workweek on MS SQL 2000

example:

datepart(ww,convert(datetime,'01/JAN/2005',113)) = 01
datepart(ww,convert(datetime,'31/DEC/2004',113)) = 53

with these conversions... I got my sale forecast data incorrect! can anyone help me solve this problem? It happened every year.

I want it like this

this is date format "dd/MMM/YYYY"

when 31/DEC/2004 is week 53 and 01/JAN/2005 should be week 53 as well. Because 07/JAN/2005 suppose to be the first week of the year. Unless 01/JAN/2005 fall on Monday.

show I write a store procedure to get the correct answer?
LVL 1
cwteohAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

imran_fastCommented:
CREATE PROCEDURE dbo.GETWEEK_STARTDATE  @DATE DATETIME,@WEEKNUM AS TINYINT OUTPUT
AS
BEGIN
SET DATEFIRST 7
DECLARE
     @START_DATE DATETIME,
     @FIRSTWEEKDAY AS TINYINT
     SET @FIRSTWEEKDAY = 1
SELECT @START_DATE = '1/1/'+ CAST(DATEPART(year,getdate()) AS VARCHAR(4))


WHILE DATEPART(weekday, @START_DATE) <> 1
BEGIN
     SET @FIRSTWEEKDAY =@FIRSTWEEKDAY + 1
     SET @START_DATE = dateadd(day, 1, @START_DATE)
     
END

     WHILE @DATE NOT BETWEEN dateadd(day,@WEEKNUM-1,@START_DATE) AND dateadd(day,6*@WEEKNUM,@START_DATE)
     SET @WEEKNUM= @WEEKNUM +1
     
END
GO
--
-- CALLING THE PROCEDURE
-- ================
-- DECLARE @WEEKNUM  INT
-- EXEC GETWEEK_STARTDATE '01/JAN/2005', @WEEKNUM OUTPUT
-- SELECT @WEEKNUM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imran_fastCommented:
hi
Is this solution working for you or you need further assistance?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
point split
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.