sql server 時間格式不同意處理yyyy_m轉換成yyyy_mm

 

圖中出現了兩種時間格式yyyy_mm和yyyy_m,需要把yyyy_m時間格式轉換成yyyy_mm;

解決方案,通過用cas when 和len函數處理。

 

select case when len(time)=6 then REPLACE(CONVERT(varchar(10),time,120),N'-','-0') else time end as time
from  test where FReportDateStr='2019-3'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章