码迷,mamicode.com
首页 > 数据库 > 详细

SQL 从身份证号得到出生日期、年龄、男女

时间:2016-08-23 07:59:53      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

 

select  CONVERT(varchar(100), CONVERT(smalldatetime, SUBSTRING(b.IDCard, 7, 8)), 23) AS BrithDate_Name, 
        DATEDIFF(year, CONVERT(smalldatetime, SUBSTRING(ISNULL(b.IDCard, 0), 7, 8)), GETDATE()) AS Age_Name, 
        CASE LEFT(RIGHT(b.IDCard, 2), 1) % 2 WHEN 1 THEN  ELSE  END AS Sex_Name,
 b.IDCard from dbo.tbEmployee b where len(b.IDCard)=18

 

select  CONVERT(varchar(100), CONVERT(smalldatetime, SUBSTRING(IDCard, 7, 8)), 23) AS BrithDate_Name, 
                      DATEDIFF(year, CONVERT(smalldatetime, SUBSTRING(ISNULL(IDCard, 0), 7, 8)), GETDATE()) AS Age_Name, 
                      CASE LEFT(RIGHT(IDCard, 2), 1) % 2 WHEN 1 THEN  ELSE  END AS Sex_Name,
        IDCard,* from dbo.tbEmployee  where len(IDCard)=18

 

SQL 从身份证号得到出生日期、年龄、男女

标签:

原文地址:http://www.cnblogs.com/yimeishui/p/5797881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!