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
 New to SQL Server Programming
 update time in datetime field

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2013-11-11 : 10:31:55
I want to update the time in a datetime field with the current time.

Fields current value is:
2013-11-11 00:00:00.000

I want to insert this into another table and when I do I want to grab the current time and update that field.

field name: picked_dt
Table: oeordlin

or is there a way through sql to update the time when the picked_dt is updated?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-11-11 : 11:15:46
one way is like this:

update oeordlin set
picked_dt = getdate()
output deleted.picked_dt
into otherTable(picked_dt)
from oeordlin
--WHERE ....


EDIT:
don't forget a WHERE clause if there is more than one row in oeordlin

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-11 : 11:42:08
i think this based on OPs description

INSERT OtherTable (DateField, other columns...)
SELECT DATEADD(dd,-DATEDIFF(dd,0,GETDATE()),GETDATE()) + picked_dt, other columns...
FROM oeordlin


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -