Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I want to update the time in a datetime field with the current time. Fields current value is:2013-11-11 00:00:00.000I 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_dtTable: oeordlinor 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_dtinto 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 OptimizerTG
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs