(turn) SQL-based EAN-13 barcode check bit generation

Source: Internet
Author: User

Source: 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 (), b bit)

INSERT INTO @t (b)
Select top 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 @[email protected]*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 @[email Protected][email protected]
Return left (reverse (@value), +ltrim) (10-len (@s1))
End
Go

SELECT dbo. Ean_13 (' 234235654652 ') ean13
Go

Drop function ean_13

/*
Ean13
-------------
2342356546528

(The number of rows affected is 1 rows)
*/

(turn) SQL-based EAN-13 barcode check bit generation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.