In my ecommerce portal I receive products EAN codes from distributors. I want to complete EAN-12 codes computing the checksum digit, and so returning the EAN-13.
Original codes are read from a SQL Server table and are copied in another SQL Server database through a stored procedure.
I would like to compute the checksum digit inside the existing stored procedure, without adding other programming layers. The algorithm for computing the checksum is based on a digit mask (it multiplies the EAN digits by positional weight values, sums the results and computes the difference with the next greater 10 multiple).
Quite easy, a UDF could implement the algorithm, but it requires to use a temp table to handle the operations on the digits and SQL Server does not allow using temp tables inside UDF!! Do you know any work around?
Algorithm details and sample:
EAN-12: 7 2 5 1 8 4 6 6 0 4 0 5
weights: 1 3 1 3 1 3 1 3 1 3 1 3
multip: 7 6 5 3 8 12 6 18 0 12 0 15
sum: 92
checksum: 8 (= 100 - 92)
10equal to100 - 92? I'm sorry if it's a dumb question to you, I know nothing about EAN-12/13.