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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - 邵印中

DBF数据库资料 DELPHI高精度计时方法,取毫秒级时间精度 电脑不能开机之U盘问题 电脑自动关机之CPU风扇烧坏 广州小灵通呼叫转移 - 邵印中 - 博客园 数字电视,方便了谁 解决连接SQL Server 2000的TCP/IP错误的Bug 商品EAN13条码的生成 关于错误“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 学习资源
商品条码的生成
邵印中 · 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语句,相当方便。