`
YTWY001
  • 浏览: 29538 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

SQL日月年转换年月日

阅读更多

方法比较砍,请高手赐教!

--第一步查出日期在前且不包含0的 修改添加0

select elder_name,birthrate as olddate,'0'+birthrate as newdate  from t_elder_base_info 
where birthrate!='' and substring(birthrate,2,1)='-' 

update t_elder_base_info set birthrate = '0'+ birthrate  
where birthrate!='' and substring(birthrate,2,1)='-' 

 
--第二步查询出日期在前面的 修改至后面 (日月年修改为年月日格式)

select elder_name,birthrate as olddate,substring(birthrate,7,4)+substring(birthrate,3,3) +'-'+substring(birthrate,1,2) as newdate 
from t_elder_base_info 
where birthrate!='' and substring(birthrate,3,1)='-' 

update t_elder_base_info set 
birthrate = substring(birthrate,7,4) + substring(birthrate,3,3) + '-'+substring(birthrate,1,2) 
where birthrate!='' and substring(birthrate,3,1)='-' 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics