php中文网 | cnphp.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 583|回复: 0

15位身份证号生成18位身份证号函数

[复制链接]

3103

主题

3113

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

UID
1
威望
0
积分
7856
贡献
0
注册时间
2021-4-14
最后登录
2024-11-10
在线时间
758 小时
QQ
发表于 2022-6-27 23:11:17 | 显示全部楼层 |阅读模式
create FUNCTION [dbo].[F_15t18](@idcaid varchar(20))
RETURNS varchar(20)
AS
BEGIN
declare @s int
set @idcaid=ltrim(rtrim(@idcaid))
if len(@idcaid)!=15
return ''
set @idcaid=LEFT(@idcaid,6) + '19' +right(@idcaid,9)
set @s=(cast(substring(@idcaid,1,1) as int)*7
+cast(substring(@idcaid,2,1) as int)*9
+cast(substring(@idcaid,3,1) as int)*10
+cast(substring(@idcaid,4,1) as int)*5
+cast(substring(@idcaid,5,1) as int)*8
+cast(substring(@idcaid,6,1) as int)*4
+cast(substring(@idcaid,7,1) as int)*2
+cast(substring(@idcaid,8,1) as int)*1
+cast(substring(@idcaid,9,1) as int)*6
+cast(substring(@idcaid,10,1) as int)*3
+cast(substring(@idcaid,11,1) as int)*7
+cast(substring(@idcaid,12,1) as int)*9
+cast(substring(@idcaid,13,1) as int)*10
+cast(substring(@idcaid,14,1) as int)*5
+cast(substring(@idcaid,15,1) as int)*8
+cast(substring(@idcaid,16,1) as int)*4
+cast(substring(@idcaid,17,1) as int)*2) % 11
if @s=0 set @idcaid=@idcaid+'1'
if @s=1 set @idcaid=@idcaid+'0'
if @s=2 set @idcaid=@idcaid+'X'
else set @idcaid=@idcaid+cast(12-@s as char(1))
RETURN @idcaid
END

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|php中文网 | cnphp.com ( 赣ICP备2021002321号-2 )

GMT+8, 2024-11-11 03:48 , Processed in 0.224437 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

申明:本站所有资源皆搜集自网络,相关版权归版权持有人所有,如有侵权,请电邮(fiorkn@foxmail.com)告之,本站会尽快删除。

快速回复 返回顶部 返回列表