Try the next script:
alter table Attendance drop column LogDate
alter table Attendance add LogDate as cast(ClockedDate as date)
Check if it worked using select * from Attendance.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a table
Create table Attendance(id int, ClockedDate datetime, LogDate datetime)
values
(1, 2019-02-25 08:52:15.000, null),
(2, 2019-02-25 08:57:51.000, null)
I want to alter the column LogDate to store date part only from ClockedDate column in the table Attendance
Please help how to alter the existing column to get the date from another column virtually.
Try the next script:
alter table Attendance drop column LogDate
alter table Attendance add LogDate as cast(ClockedDate as date)
Check if it worked using select * from Attendance.
Hi @Polachan Paily ,
Do you consider using the update statement?
alter table Attendance alter column LogDate date null;
update Attendance
set LogDate=cast(ClockedDate as date)
from Attendance
select * from Attendance
Output:
id ClockedDate LogDate
1 2019-02-25 08:52:15.000 2019-02-25
2 2019-02-25 08:57:51.000 2019-02-25
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.