【叶子函数分享十三】根据身份证计算性别函数

Go --创建函数(函数来自csdn,作者不详) create function [dbo].[Get_sex] ( @idcardno nvarchar(50) ) returns int as begin declare @sex int if (len(@idcardno)=18 and isnumeric(substring(@idcardno,17,1))=1 ) set @sex= (case when substring(@idcardno,17,1) in(1,3,5,7,9) then 1 when substring(@idcardno,17,1) in(2,4,6,7,0) then 2 else 0 end) else if (len(@idcardno)=15 and isnumeric(substring(@idcardno,15,1))=1 ) set @sex= (case when substring(@idcardno,15,1) in(1,3,5,7,9) then 1 when substring(@idcardno,15,1) in(2,4,6,7,0) then 2 else 0 end) else set @sex=0 return(@sex) end --测试示例 select dbo.[Get_sex]('222222198306043213') --运行结果(1表示男0表示女) /* 1 */ 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/maco_wang/archive/2011/03/19/6261542.aspx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值