DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

EAN13 Check With SQL

08.05.2009
| 3555 views |
  • submit to reddit
        
SELECT attributes_ean
FROM products_attributes
WHERE
LENGTH(attributes_ean) = 13
AND
SUBSTRING((10 - ((((
SUBSTRING(attributes_ean FROM 2 FOR 1) +
SUBSTRING(attributes_ean FROM 4 FOR 1) +
SUBSTRING(attributes_ean FROM 6 FOR 1) +
SUBSTRING(attributes_ean FROM 8 FOR 1) +
SUBSTRING(attributes_ean FROM 10 FOR 1) +
SUBSTRING(attributes_ean FROM 12 FOR 1)  
)*3) + (
SUBSTRING(attributes_ean FROM 1 FOR 1) +
SUBSTRING(attributes_ean FROM 3 FOR 1) +
SUBSTRING(attributes_ean FROM 5 FOR 1) +
SUBSTRING(attributes_ean FROM 7 FOR 1) +
SUBSTRING(attributes_ean FROM 9 FOR 1) +
SUBSTRING(attributes_ean FROM 11 FOR 1)
)) MOD 10)) FROM -1 FOR 1) != SUBSTRING(attributes_ean FROM 13 FOR 1)