【叶子函数分享十二】根据身份证得到生日函数
2011-04-12 09:20
211 查看
go
--创建函数(函数来自csdn,作者不详)
create function [dbo].[Get_birthday]
(
@idcardno nvarchar(50)
)
returns varchar(10)
as
begin
declare @birthday datetime
if (len(@idcardno)=15 or len(@idcardno)=16) and substring(@idcardno,9,2) between 1 and 12 and substring(@idcardno,11,2) between 1 and 31
set @birthday= convert(varchar(10),'19'+substring(@idcardno,7,2)+'-'+substring(@idcardno,9,2)+'-'+substring(@idcardno,11,2),120)
else if len(@idcardno)=18 and substring(@idcardno,7,2)>=19 and substring(@idcardno,11,2) between 1 and 12 and substring(@idcardno,13,2) between 1 and 31
set @birthday= convert(varchar(10),substring(@idcardno,7,4)+'-'+substring(@idcardno,11,2)+'-'+substring(@idcardno,13,2),120)
else
set @birthday=null
return(convert(varchar(10),@birthday,120))
end
--测试示例
select dbo.[Get_birthday]('222222198306043213')
--运行结果
/*
1983-06-04
*/
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/maco_wang/archive/2011/03/19/6261536.aspx
--创建函数(函数来自csdn,作者不详)
create function [dbo].[Get_birthday]
(
@idcardno nvarchar(50)
)
returns varchar(10)
as
begin
declare @birthday datetime
if (len(@idcardno)=15 or len(@idcardno)=16) and substring(@idcardno,9,2) between 1 and 12 and substring(@idcardno,11,2) between 1 and 31
set @birthday= convert(varchar(10),'19'+substring(@idcardno,7,2)+'-'+substring(@idcardno,9,2)+'-'+substring(@idcardno,11,2),120)
else if len(@idcardno)=18 and substring(@idcardno,7,2)>=19 and substring(@idcardno,11,2) between 1 and 12 and substring(@idcardno,13,2) between 1 and 31
set @birthday= convert(varchar(10),substring(@idcardno,7,4)+'-'+substring(@idcardno,11,2)+'-'+substring(@idcardno,13,2),120)
else
set @birthday=null
return(convert(varchar(10),@birthday,120))
end
--测试示例
select dbo.[Get_birthday]('222222198306043213')
--运行结果
/*
1983-06-04
*/
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/maco_wang/archive/2011/03/19/6261536.aspx
相关文章推荐
- 【叶子函数分享十二】根据身份证得到生日函数
- 【叶子函数分享四十八】根据年得到所有星期日的日期
- 【叶子函数分享二十七】根据日期得到星期的函数
- 【叶子函数分享二十七】根据日期得到星期的函数
- 根据身份证得到生日函数
- SQL函数根据身份证得到生日函数
- 【叶子函数分享三十九】根据年月得到当月的天数
- 【叶子函数分享二十七】根据日期得到星期的函数
- 【叶子函数分享四十八】根据年得到所有星期日的日期
- 【叶子函数分享十三】根据身份证计算性别函数
- 根据身份证得到生日函数
- 【叶子函数分享十三】根据身份证计算性别函数
- 【叶子函数分享九】根据字符分割字符串的三种写法
- [MSSQL]【叶子函数分享二十八】根据年度判断是否是闰年
- 【叶子函数分享二十八】根据年度判断是否是闰年
- 【叶子函数分享二十二】根据日期返回星座
- 15位, 18位的身份证号码的验证函数.以及根据身份证取省份,生日,性别
- 【叶子函数分享三十八】得到条形码的校验位函数
- 【叶子函数分享二十四】根据年月生成日历函数
- vbscript和javascript版的15位, 18位的身份证号码的验证函数.以及根据身份证取省份,生日,性别