sql 修改日期字段的格式

废话不多说,直接上sql:

UPDATE db_huanjing_GM_YanQing_TEST.dbo.GM_AY_yiqi_copy
SET jiandingriqi = concat(Datepart(yyyy, CAST(jiandingriqi AS datetime)), IIF(Datepart(mm, CAST(jiandingriqi AS datetime)) > 9, concat('年', Datepart(mm, CAST(jiandingriqi AS datetime))), concat('年0', Datepart(mm, CAST(jiandingriqi AS datetime)))), IIF(Datepart(dd, CAST(jiandingriqi AS datetime)) > 9, concat('月', Datepart(dd, CAST(jiandingriqi AS datetime))), concat('月0', Datepart(dd, CAST(jiandingriqi AS datetime)))), '日')
WHERE jiandingriqi != '';

效果:例如:2019.2.18   ====>>>> 2019年02月18日

你可能感兴趣的:(sql,sql优化,sql)