EAN13 Check With SQL
Join the DZone community and get the full member experience.
Join For Free
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)
sql
Opinions expressed by DZone contributors are their own.
Comments