写了个15位身份证号升级为18位的SQL语句

-- 15位身份证号升级为18位,适用于18xx年出生的公民
UPDATE 员工表 SET 身份证号 =
 
SUBSTRING (身份证号, 1 , 6 ) + ' 18 ' + SUBSTRING (身份证号, 7 , 9 ) +
 
SUBSTRING ( ' 10X98765432 ' ,
  (
  
CAST ( SUBSTRING (身份证号, 1 , 1 ) AS INT ) * 7
 
+ CAST ( SUBSTRING (身份证号, 2 , 1 ) AS INT ) * 9
 
+ CAST ( SUBSTRING (身份证号, 3 , 1 ) AS INT ) * 10
 
+ CAST ( SUBSTRING (身份证号, 4 , 1 ) AS INT ) * 5
 
+ CAST ( SUBSTRING (身份证号, 5 , 1 ) AS INT ) * 8
 
+ CAST ( SUBSTRING (身份证号, 6 , 1 ) AS INT ) * 4
 
+ 1 * 2
 
+ 8 * 1
 
+ CAST ( SUBSTRING (身份证号, 7 , 1 ) AS INT ) * 6
 
+ CAST ( SUBSTRING (身份证号, 8 , 1 ) AS INT ) * 3
 
+ CAST ( SUBSTRING (身份证号, 9 , 1 ) AS INT ) * 7
 
+ CAST ( SUBSTRING (身份证号, 10 , 1 ) AS INT ) * 9
 
+ CAST ( SUBSTRING (身份证号, 11 , 1 ) AS INT ) * 10
 
+ CAST ( SUBSTRING (身份证号, 12 , 1 ) AS INT ) * 5
 
+ CAST ( SUBSTRING (身份证号, 13 , 1 ) AS INT ) * 8
 
+ CAST ( SUBSTRING (身份证号, 14 , 1 ) AS INT ) * 4
 
+ CAST ( SUBSTRING (身份证号, 15 , 1 ) AS INT ) * 2
  )
 
% 11 + 1 , 1 )
WHERE LEN (身份证号) = 15 AND SUBSTRING (身份证号, 13 , 3 ) IN ( ' 999 ' , ' 998 ' , ' 997 ' , ' 996 ' )

-- 15位身份证号升级为18位,适用于19xx年出生的公民
UPDATE 员工表 SET 身份证号 =
 
SUBSTRING (身份证号, 1 , 6 ) + ' 19 ' + SUBSTRING (身份证号, 7 , 9 ) +
 
SUBSTRING ( ' 10X98765432 ' ,
  (
  
CAST ( SUBSTRING (身份证号, 1 , 1 ) AS INT ) * 7
 
+ CAST ( SUBSTRING (身份证号, 2 , 1 ) AS INT ) * 9
 
+ CAST ( SUBSTRING (身份证号, 3 , 1 ) AS INT ) * 10
 
+ CAST ( SUBSTRING (身份证号, 4 , 1 ) AS INT ) * 5
 
+ CAST ( SUBSTRING (身份证号, 5 , 1 ) AS INT ) * 8
 
+ CAST ( SUBSTRING (身份证号, 6 , 1 ) AS INT ) * 4
 
+ 1 * 2
 
+ 9 * 1
 
+ CAST ( SUBSTRING (身份证号, 7 , 1 ) AS INT ) * 6
 
+ CAST ( SUBSTRING (身份证号, 8 , 1 ) AS INT ) * 3
 
+ CAST ( SUBSTRING (身份证号, 9 , 1 ) AS INT ) * 7
 
+ CAST ( SUBSTRING (身份证号, 10 , 1 ) AS INT ) * 9
 
+ CAST ( SUBSTRING (身份证号, 11 , 1 ) AS INT ) * 10
 
+ CAST ( SUBSTRING (身份证号, 12 , 1 ) AS INT ) * 5
 
+ CAST ( SUBSTRING (身份证号, 13 , 1 ) AS INT ) * 8
 
+ CAST ( SUBSTRING (身份证号, 14 , 1 ) AS INT ) * 4
 
+ CAST ( SUBSTRING (身份证号, 15 , 1 ) AS INT ) * 2
  )
 
% 11 + 1 , 1 )
WHERE LEN (身份证号) = 15 AND SUBSTRING (身份证号, 13 , 3 ) NOT IN ( ' 999 ' , ' 998 ' , ' 997 ' , ' 996 ' )
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值