惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
B
Blog
月光博客
月光博客
博客园 - 【当耐特】
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
博客园 - Franky
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
B
Blog RSS Feed
H
Help Net Security

博客园 - 邵印中

DBF数据库资料 DELPHI高精度计时方法,取毫秒级时间精度 电脑不能开机之U盘问题 电脑自动关机之CPU风扇烧坏 广州小灵通呼叫转移 - 邵印中 - 博客园 数字电视,方便了谁 解决连接SQL Server 2000的TCP/IP错误的Bug 商品条码的生成 关于错误“Cannot connect to the Citrix MetaFrame server.Can't assign requested address”的解决方法 电脑死机之CPU温度过高 winrar 8 注册方法 "加载类型库/dll时出错" 的解决方法 删除子窗体中的控件中的某些属性时出现"Selection contains a component introduced in an ancestor form which cannot be deleted."错误的解决方法 SC命令配置服务 SQL 2005如何更改服务器身份验证模式 There is no Citrix MetaFrame server configured on the specified address错误的解决方法 ASP.NET AJAX,WCF,ADO.NET Entity 开发实例 Citrix 客户端登录出现wfshell.exe - 应用程序错误的解决方法 WCF 学习资源
商品EAN13条码的生成
邵印中 · 2009-07-26 · via 博客园 - 邵印中

最近客户要求在货品资料中生成商品条码(即EAN13,国际商品条码),虽然系统中有商品条码生成的工具,但是对不上号,根本无法使用,客户的货品资料已经有部分有条码,更重要的是客户要求生成商品条码的货品无法正常筛选出来(比如:GW开头,或者是GM开头,而且要求的是GW和GM后面全是数字的货品才要求生成),客户又急着用,没有办法的情况下,就自己动手写了一个小工具,虽然客户无法使用,但是对于维护客户的商品条码生成,确是相当的方便,现记录下,以便将来查看:
生成EAN13条码的SQL函数代码:
create function dbo.EAN13(@value varchar(13))
    returns varchar(13)
as
begin
    declare @s1 int ,@s2 int ,@s3 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 @s3=right(@s1+@s2,1)
return left(reverse(@value),12)+ltrim(10-case @s3 when '0' then '10' else @s3 end)
end
go
函数调用:
select dbo.ean13(694386035966) 返回值:6943860359663
在程序中执行时,可以手工写入SQL语句,这样,可以自由的提出要生成的货品资料,例如:
select code,name,standardcode from goods where (patindex('GW[0-9]%',Code)>0 or patindex('GM[0-9]%',Code)>0) and
(standardcode is  null)
动态的指定SQL语句,相当方便。