all groups > sql server programming > may 2007 >
You're in the

sql server programming

group:

Update question


Update question Tango
5/10/2007 9:48:01 PM
sql server programming:
Hi
i have a table with a date & week field
the week number is 1,2,3 or 4
so as you scroll down the date there is 7 1's then 7 2's then 7 3's then 7
4's then 7 1's & so on.

This process starts from a specific date.

is there any way to do an update statement on this ?

Re: Update question David Portas
5/10/2007 10:52:07 PM
[quoted text, click to view]


In the following example the start date for week 1 is 2001-01-01.

UPDATE Calendar
SET WeekNum = FLOOR(DATEDIFF(DAY,'20010101',CalDate)/7.0);

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Re: Update question Tango
5/10/2007 11:34:02 PM
thank you David,

i cant see where the range goes bact to 1 after doing 7 lots of 1, then 7
lots of 2 then seven lots of 3, then seven lots of 4

the weeks are 1,2,3,4,1,2,3,4 etc

regards

todd

[quoted text, click to view]
Re: Update question Razvan Socol
5/11/2007 12:08:38 AM
Hi, Tango

Try something like this:

UPDATE Calendar SET Week=
(DATEDIFF(d,DATEADD(m,DATEDIFF(m,0,Date),0),Date)+1)/7+1

Razvan

[quoted text, click to view]
Re: Update question Tango
5/11/2007 12:22:00 AM
thanks for the prompt responses, ireally appreciate it

i still cant see how the query knows when to stop at 4 & go back to 1

regards

todd

[quoted text, click to view]
Re: Update question Razvan Socol
5/11/2007 6:54:25 AM
Maybe you want something like this:

UPDATE Calendar SET Week=(DATEDIFF(d,'20070201',Data)/7%4)+1

(you can change 1 feb 2007 with the desired date)

Razvan
AddThis Social Bookmark Button