How would I go about updating existing DateTime columns in an update statement?
I’d like to subtract one day but I get an error message saying that I cannot use DateAdd in an update (something about an overflow).
I came up with this query but of course it will not execute.
begin tran upd
update answer
set SentForApprovalAt = DateAdd(day, -1, approvedAt)
where
approvedAt > '1753-01-01'
and approvedAt < modifiedAt
commit tran upd
What do I do?
The reason you’re receiving this error is likely because the date you’re attempting to subtract 1 from is causing the resultant value to be less than the minimum value for a TSQL datetime.
Using the following testcase: