EAN13 check with SQL
0
Updated over 10 years ago (07 Aug 2009 at 05:03 AM)
recent activity
In Brief | Verify the EAN13 Checksum with (My)SQL. Output invalid EAN Numbers.... more |
Language | MySQL |
# 's
1SELECT attributes_ean
2FROM products_attributes
3WHERE
4LENGTH(attributes_ean) = 13
5AND
6SUBSTRING((10 - ((((
7SUBSTRING(attributes_ean FROM 2 FOR 1) +
8SUBSTRING(attributes_ean FROM 4 FOR 1) +
9SUBSTRING(attributes_ean FROM 6 FOR 1) +
10SUBSTRING(attributes_ean FROM 8 FOR 1) +
11SUBSTRING(attributes_ean FROM 10 FOR 1) +
12SUBSTRING(attributes_ean FROM 12 FOR 1)
13)*3) + (
14SUBSTRING(attributes_ean FROM 1 FOR 1) +
15SUBSTRING(attributes_ean FROM 3 FOR 1) +
16SUBSTRING(attributes_ean FROM 5 FOR 1) +
17SUBSTRING(attributes_ean FROM 7 FOR 1) +
18SUBSTRING(attributes_ean FROM 9 FOR 1) +
19SUBSTRING(attributes_ean FROM 11 FOR 1)
20)) MOD 10)) FROM -1 FOR 1) != SUBSTRING(attributes_ean FROM 13 FOR 1)
Verify the EAN13 Checksum with (My)SQL. Output invalid EAN Numbers.
This example is using the xt:commerce DB structure.
Add a Comment