Notebook
Documentation
Online POS
More

Converting barcodes with Addon


A store that sells a large number of magazines had a general level of untidiness in their barcodes. Barcodes had been recorded including the addon in many cases which meant that for each issue change of the magazine the barcode would no longer work.

What are addons?

Addon barcodes are an additional small barcode beside the main barcode. They are generally used for issue based items to indicate the issue number. The main barcode remains the same from issue to issue, but the addon changes. Addons are typically 2 digits long for magazines, although they can be 2 or 5 digits.

Analysis and Solution

A normal magazine barcode is typically 12 or 13 digits long. When stored with the addon in the database they become 14 or 15 digits long.

SQL to execute

The following SQL commands were used to split the barcodes with addons included and store only the stem part, if it was not already present. Normally direct physical access to the database is discouraged, but in this case the need to do this is probably a one off occurrance and a 90% solution is all that is required. Errors and exceptions can be manually corrected by instore staff.

 insert into barcodes (pid, barcode, manflags) 
 select pid,substring(b.barcode,0,13),1 from barcodes b
 where datalength(barcode)=14
 and substring(b.barcode,0,13) not in (select z.barcode from barcodes z where z.pid=b.pid)
 group by pid,substring(b.barcode,0,13)

 insert into barcodes (pid, barcode, manflags) 
 select pid,substring(b.barcode,0,14),1 from barcodes b
 where datalength(barcode)=15
 and substring(b.barcode,0,14) not in (select z.barcode from barcodes z where z.pid=b.pid)
 group by pid,substring(b.barcode,0,14)