时间:2021-07-01 10:21:17 帮助过:64人阅读
源:http://bbs.csdn.net/topics/220057226
create function dbo.EAN_13(@value varchar(13))
returns varchar(13)
as
begin
declare @s1 int ,@s2 int
declare @t table (id int identity(1,1),b bit)
insert into @t(b)
select top 13 1 from syscolumns
set @value=‘0‘+reverse(@value)
select @s1=sum(cast(substring(@value,id,1) as int))
from @t a
where len(@value)>=id and id%2=0
set @s1=@s1*3
select @s2=sum(cast(substring(@value,id,1) as int))
from @t a
where len(@value)>=id and id>=3 and id%2=1
set @s1=@s1+@s2
return left(reverse(@value),12)+ltrim(10-len(@s1))
end
go
select dbo.EAN_13(‘234235654652‘) ean13
go
drop function EAN_13
/*
ean13
-------------
2342356546528
(所影响的行数为 1 行)
*/
(转)基于SQL的EAN-13条形码校验位生成
标签:str varchar drop http creat arc where eve entity