Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Update a date column

Author  Topic 

rama.nelluru
Starting Member

37 Posts

Posted - 2011-10-27 : 21:33:40
Hi ,

I need to write a script that updates the date columns.

My requirement is

I have date column

Col name-----Datecol
01-10-2010
01-17-2010
01-24-2010.......with a week diffrnce

I need to update 01-10-2010 with the 04-06-2010
01-10-2010 with the 04-13-2010( a week diffrence hear)

so finally the first date(01-10-2010) must be update with 04-06-2010...a week diffrnce in both the dates....
I need to channge like 12 weeks like that.

Please help me on this....



RAM

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-27 : 22:41:22
look up dateadd in Books online...you do know what bol is?


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-28 : 05:36:59
see this at least if you cant refer bol

http://msdn.microsoft.com/en-us/library/ms186819.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rama.nelluru
Starting Member

37 Posts

Posted - 2011-10-28 : 08:36:52
I have table with column name datecol data
-------
01-10-2010
01-17-2010
01-24-2010

and in other table or same table i have datecolumn with data
04-10-2012
04-17-2012
04-24-2012

I want update if 01-10-2010 was the date i need to update with 04-10-2012
if 01-17-2010 was the date i need to update with 04-10-2012
like that i need to update foe 10 continous weeks.

Please some one can help me to write a script that updates the date with 1 week diffrence in the tables column.

RAM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-28 : 08:42:34
one question. how do you determine which date in your first table needs to replaced by which date in other table? do you have a common field with which you can relate them?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-28 : 09:53:50
DATEDIFF(dd, DAtecol, Getdate()) < 10

???

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

rama.nelluru
Starting Member

37 Posts

Posted - 2011-10-28 : 11:46:37
common field is weekid. How do I update the teh date. Please any someone can help me out the script

RAM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-28 : 11:57:30
quote:
Originally posted by rama.nelluru

common field is weekid. How do I update the teh date. Please any someone can help me out the script

RAM



Sure, Read my link in my sig, or Post the DDL, some sample Data in DML Form and what the expected results are suppose to be...

If that's too much work, well, then...good luck

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-28 : 12:27:03
quote:
Originally posted by rama.nelluru

common field is weekid. How do I update the teh date. Please any someone can help me out the script

RAM


can we see what update query you tried and what was issue you faced with it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -