首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL岁月年转换年月日

2012-07-24 
SQL日月年转换年月日方法比较砍,请高手赐教!--第一步查出日期在前且不包含0的 修改添加0select elder_name

SQL日月年转换年月日

方法比较砍,请高手赐教!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)='-' 

?

?

热点排行