我有一个日期时间列,它将记录存储为
2020 年 3 月 10 日 12:00
但想将所有格式更改为 03/10/20
有上千条记录
我试过了,
COnvert(date,convert(varchar, PostingDate, 101),101)
我假设该列实际上是一个字符串,而不是
datetime
。
SQL Server 迄今为止具有相当灵活的转换。首先检查以确保所有日期都已转换:
select col
from t
where try_convert(date, col) is null and col is not null;
如果您对转换感到满意,您可以执行以下操作:
update t
set col = try_convert(date, col);
alter table t alter col date;
要更改表中列的数据类型,请使用以下语法:
SQL Server / MS Access:
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
ALTER TABLE Employee
ALTER COLUMN Dates Date;