首页 优化推广 通过身份证分析出生年月日、性别、年龄的SQL语句

通过身份证分析出生年月日、性别、年龄的SQL语句

来源: | 时间:2014/3/3 10:28:39 |

update [表名] set [性别]=(case when (left(right([身份证],2),1) % 2 = 0) then '女' else '男' end ) where len([身份证])=18 and left(right([身份证],2),1)<>'X'
update [表名] set [性别]=(case when (right([身份证],1) % 2 = 0) then '女' else '男' end ) where len([身份证])=15 and right([身份证],1)<>'X'
update [表名] set [出生日期]=(right(left([身份证],10),4)+'-'+right(left([身份证],12),2)+'-'+right(left([身份证],14),2)) where len([身份证])=18
update [表名] set [出生日期]=('19'+right(left([身份证],8),2)+'-'+right(left([身份证],10),2)+'-'+right(left([身份证],12),2)) where len([身份证])=15
update [表名] set [年龄]=year(getdate())-(cast(left([出生日期],4) as int)) where [出生日期]<>''

服务热线

153 8323 9821

功能和特性

价格和优惠

网站和维护

推广和优化

微信服务号