I have a table with 43 000 000 rows. In datetime column data looks 2020.04.22T04:39:29.359
and it's of type VARCHAR
.
It looks like an ISO format but there are .
, and for ISO I need -
.
What is the best way to convert the values in these rows to datetime?
One of my variant was subst . to -:
UPDATE table
SET [Column 3] = REPLACE([Column 3], '.', '-');
but then I need to cut a microseconds from the end.
How to do this cut?
Or maybe you can advice more truish way.
VARCHAR
." The real question is why are you using avarchar
in the first place? Fix the design, fix the problem. – Larnu Nov 29 '20 at 11:14DATETIME
, unlikeDATETIME2
, does not support full precision in the milliseconds, it's only accurate (if you can call it that) to 3 milliseconds. A value like04:39:29.359
in particular cannot be exactly represented and will be rounded to04:39:29.360
. For some applications this doesn't matter, for others it does (when data has to be compared to the original). So whileVARCHAR
is definitely not the right type to use,DATETIME
isn't necessarily either. – Jeroen Mostert Nov 29 '20 at 20:43