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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to update datepart day

Author  Topic 

sonial8
Starting Member

5 Posts

Posted - 2009-09-28 : 15:16:20
How would I update a date part day in the table.

I want to update all records for an id where date is 2009-07-25:00:00.. to July 30, I want to retain the timestamp hence only want to update the day portion of the date.

update tablename set datepart(dd, name of column)??

Thanks in advance.
Sonia

sonia

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-28 : 15:18:53
Just use DATEADD to add 5 days.

UPDATE t1
SET Column1 = DATEADD(dd, 5, Column1)
WHERE Column1 >= '07-25-2009' AND Column1 < '07-26-2009'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

sonial8
Starting Member

5 Posts

Posted - 2009-09-28 : 15:21:37
TKizer you are awesome! thanks much this worked

sonia
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-28 : 15:23:27
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -