34,587
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: @T
declare @T table (col varchar(13))
insert into @T
select 8271231212124 union all
select 1231228892828 union all
select 1237884919213 union all
select 4683829191026 union all
select 2499583891217 union all
select 6901028075013
--得到不对的,并显示正确的情况
select
col as 错误值,
dbo.[Get_CheckCode](col) as 正确值
from @T
where col<>dbo.[Get_CheckCode](col)
/*
错误值 正确值
------------- -------------
4683829191026 4683829191027
6901028075013 6901028075015
*/
/**
--功能:获取EAN-13码的检验位
--Author:josy(百年树人)
--参数@s:EAN-13码前12位
**/
create function EAN13(@s char(12))
returns varchar(1)
as
begin
return (10-(
(cast(substring(@s,2,1) as int)+substring(@s,4,1)+substring(@s,6,1)
+substring(@s,8,1)+substring(@s,10,1)+substring(@s,12,1)
)*3
+substring(@s,1,1)+substring(@s,3,1)+substring(@s,5,1)
+substring(@s,7,1)+substring(@s,9,1)+substring(@s,11,1)
)%10)%10
end
go
select dbo.ean13(left('6901028075013',12))
/**
----
5
(1 行受影响)
**/
--drop function ean13