展开全部

像这样写个视图就行了:

create View eVMutiCard

AS

Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,

b.Identification,

N'身份证长32313133353236313431303231363533e58685e5aeb931333262363635度不合常理' As Remark

From employee b

Where (Len(b.Identification) Not In (15,18)

And b.Identification Is Not Null )

Or b.Identification is Null

Union All

Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,

b.Identification,

N'身份证具有无效字符' As Remark

From employee b

Where Len(b.Identification) In (15,18)

And Isnumeric(Case Len(b.Identification) When 18 Then Substring(b.Identification,1,17)

Else b.Identification End) = 0

Union All

Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,

b.Identification,

N'身份证出生日期不合常理' As Remark

From employee b

Where Len(b.Identification) In (15,18)

And (IsDate(Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)

Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)

End)=0

Or Not (

(Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)

Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)

End) Between '1900-01-01' And '2079-06-06'))

Union All

Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,

b.Identification,

N'身份证校验位不正确(第18位与校验不符)' As Remark

From employee b

Where (Len(b.Identification) = 18

And substring(b.Identification,18,19) <> dbo.GetCheckIDCardCode(b.Identification)

And b.Identification Is Not Null)

其中跟据国家规定的计算公式,计算18位身份证检验位的dbo.GetCheckIDCardCode如下:

CREATE function GetCheckIDCardCode(@sfzh char(18))

returns char(1)

as

begin

declare @r varchar(2)

declare @i int

if len(@sfzh) <> 18

set @r = 0

else

set @i = cast(substring(@sfzh,1,1) as int) * 7

+cast(substring(@sfzh,2,1) as int) * 9

+cast(substring(@sfzh,3,1) as int) * 10

+cast(substring(@sfzh,4,1) as int) * 5

+cast(substring(@sfzh,5,1) as int) * 8

+cast(substring(@sfzh,6,1) as int) * 4

+cast(substring(@sfzh,7,1) as int) * 2

+cast(substring(@sfzh,8,1) as int) * 1

+cast(substring(@sfzh,9,1) as int) * 6

+cast(substring(@sfzh,10,1) as int) * 3

+cast(substring(@sfzh,11,1) as int) * 7

+cast(substring(@sfzh,12,1) as int) * 9

+cast(substring(@sfzh,13,1) as int) * 10

+cast(substring(@sfzh,14,1) as int) * 5

+cast(substring(@sfzh,15,1) as int) * 8

+cast(substring(@sfzh,16,1) as int) * 4

+cast(substring(@sfzh,17,1) as int) * 2

set @i = @i - @i/11 * 11

set @r = cast((case @i

when 0 then 1

when 1 then 0

when 2 then 11

when 3 then 9

when 4 then 8

when 5 then 7

when 6 then 6

when 7 then 5

when 8 then 4

when 9 then 3

when 10 then 2

else '' end) as char)

if (@r = 11) set @r='X'

else set @r = @r

set @r = '' + @r +''

return @r

end

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

mysql身份证校验码_sql 语句 验证身份证号码相关推荐

  1. mysql身份证校验码_mysql正则表达式验证身份证,并获取年龄、生日、性别

    mysql正则表达式验证身份证,并获取年龄.生日.性别 发布时间:2018-05-17 16:28, 浏览次数:4844 , 标签: mysql正则表达式,mysql验证身份证,REGEXP mysq ...

  2. mysql身份证校验码_用sql实现18位身份证校验代码分享 身份证校验位计算

    身份证校验码的计算方法 1.将前面的身份证号码17位数分别乘以不同的系数.第i位对应的数为[2^(18-i)]mod11.从第一位到第十七位的系数分别为:7 9 10 5 8 4 2 1 6 3 7 ...

  3. 【转载】用Python计算身份证校验码

    原来的天朝良民证是15位,构成如下:   1-6位:地址码.采用的是行政区划代码,可以去   统计局的网站   查.   7-12位:生日期码.构成为yymmdd.   13-15位:顺序码.每个地区 ...

  4. 用Python计算身份证校验码

    转自:http://my.oschina.net/moooofly/blog/147958 原来的天朝良民证是15位,构成如下:  1-6位:地址码.采用的是行政区划代码,可以去 统计局的网站 查.  ...

  5. angularjs 验证身份证格式 和 一般JS验证身份证格式

    1:angularjs 验证身份证格式 1.1 定义身份证验证指令: .directive('cardCheck',['$http','$rootScope',function($http,$root ...

  6. php验证身份证的合法性 ps:js验证身份证的合法性

    php验证的方法: /*** 验证身份证的合法性*/public function isIdCard($number){ // 检查是否是身份证号// 转化为大写,如出现x$number = strt ...

  7. mysql sql 备份表_SQL语句之备份表

    SELECT INTO 语句:表示从一个表中选取数据,然后把数据插入另一个表中,常用来备份一张表 1.全表结构备份: SELECT * INTO new_table_name FROM old_tab ...

  8. mysql单引号转义_sql语句中使用单引号'作为转义字符

    在SQL中,我们都知道单引号 ' 表示字符串的开始和结束符号,如: select * from students where name = '小明'; 但如果字符串里面有单引号时,应该怎么查询呢? 这 ...

  9. mysql where 条件先后_sql语句 where 后条件执行先后顺序

    针对mysql,其条件执行顺序是 从左往右,自上而下 针对SQL server.orcale,其条件执行顺序是从右往左,自下而上 1.mysql where执行顺序是从左往右执行的,在数据量小的时候不 ...

最新文章

  1. log4j打印mybatis sql语句
  2. oracle数据导入-dblink方式
  3. Linux运维:查看磁盘空间的大小
  4. python字典遍历取值_Python中字典的使用
  5. 动态密码卡TOTP算法
  6. 【ArcGIS风暴】在ArcGIS中实现将一个圆16等分
  7. java web框架 django_django——web框架简介
  8. 区别德语的公母阴阳性别的秘诀
  9. 互联网全球化趋势下,印度极得美自我革新
  10. qstringlist格式怎么写到txt_怎样把PDF转成TXT呢?
  11. 贪心科技机器学习训练营(二)
  12. DispatcherServlet详细分析
  13. python计算一个三位数个位数之和
  14. B站成长期UP主有哪些涨粉机会?
  15. 开发一款游戏需要服务器系统,搭建一个游戏服务器需要什么
  16. 数据治理之敏感数据探查
  17. VBA编程常用语句300句
  18. 【初等数论】整除、公约数、同余与剩余系
  19. 安鸾渗透实战平台综合渗透——SQL注入进阶渗透流程
  20. vue手风琴组件_Vue 2的Badger手风琴组件

热门文章

  1. 最新AI绘画矢量笔刷2100款大合集,支持AI2022版本
  2. 这份最新阿里、腾讯、华为、字节等大厂的薪资和职级对比,你在哪个阶段?
  3. 一文快速学会hadoop完全分布式集群搭建,很详细
  4. Detectron2系列之与其他库的兼容性
  5. 母亲节快到了 用这些APP给妈妈一个惊喜
  6. 生存危机,末日血战、末日危机攻略之英雄升级升星,每周活动详细说明
  7. 电脑版fl studio水果音乐编曲软件 v20.8新中文版
  8. 用 pip show XXX 查询Python安装库的版本等信息
  9. Polyworks脚本开发学习笔记(十九)-将数据对象与参考对象对齐的方法
  10. Excel for Mac 快捷键