2015. július 27., hétfő

EAN13 vonalkód 13. checkum karakterének kiszámoltatása magyar nyelvű Excellel

Az M4 mezőt alapul véve az EAN13 első 12 jegyét tartalmazó cellának ezzel az Excel függvénnyel gyorsan kiszámoltathatjuk a 13. karaktert:

=M4&(ROUNDUP(((KÖZÉP(M4;2;1)+KÖZÉP(M4;4;1)+KÖZÉP(M4;6;1)+KÖZÉP(M4;8;1)+KÖZÉP(M4;10;1)+KÖZÉP(M4;12;1))*3)+(KÖZÉP(M4;1;1)+KÖZÉP(M4;3;1)+KÖZÉP(M4;5;1)+KÖZÉP(M4;7;1)+KÖZÉP(M4;9;1)+KÖZÉP(M4;11;1));-1)-(((KÖZÉP(M4;2;1)+KÖZÉP(M4;4;1)+KÖZÉP(M4;6;1)+KÖZÉP(M4;8;1)+KÖZÉP(M4;10;1)+KÖZÉP(M4;12;1))*3)+(KÖZÉP(M4;1;1)+KÖZÉP(M4;3;1)+KÖZÉP(M4;5;1)+KÖZÉP(M4;7;1)+KÖZÉP(M4;9;1)+KÖZÉP(M4;11;1))))

Egyszerűen kicserélhetjük az M4 szövegrészt a szükséges cella pozíciójára akár egy jegyzettömbben (CTRL-H).

MySQL query to calculate EAN 13 checksum

The now called Global Trade Item Numbers (GTIN or GTIN 13), formerly called European Article Numbers (EAN or EAN 13) have 12 information digits and one extra for cheksum.

Using MySQL native SQL queries, you can calculate (query) the checksum number the following way:

Lets imagine a table product with a column named ean, the SQL returning the checksum for every ean row would be:

SELECT 
SUBSTRING((10 - ((((
SUBSTRING(ean FROM 2 FOR 1) +
SUBSTRING(ean FROM 4 FOR 1) +
SUBSTRING(ean FROM 6 FOR 1) +
SUBSTRING(ean FROM 8 FOR 1) +
SUBSTRING(ean FROM 10 FOR 1) +
SUBSTRING(ean FROM 12 FOR 1)  
)*3) + (
SUBSTRING(ean FROM 1 FOR 1) +
SUBSTRING(ean FROM 3 FOR 1) +
SUBSTRING(ean FROM 5 FOR 1) +
SUBSTRING(ean FROM 7 FOR 1) +
SUBSTRING(ean FROM 9 FOR 1) +
SUBSTRING(ean FROM 11 FOR 1)
)) MOD 10)) 
FROM -1 FOR 1) 
FROM product