Thanks Jonathan and Deebee,
With some minor alteration, I got this to work the way I needed.
See http://www.uc-council.org/ean_ucc_system/education_support/cdc.html
I needed to calculate EAN's and UPC's which are a little different than
the IBM Published Modulus 10 calculation.
(per deebee see
http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/QB3AUI01/3.27.1.4 )
IBM said to multiply the result of the odd numbers by two but the UPC
multiplies by three.
The tested results to calculate a check digit for UPC, EAN,
ISBN, etc are:
create function mylib.mod10 (modnumber bigint) returns smallint
language sql
begin
declare sumeven int default 0;
declare sumodd int default 0;
declare numlen int;
declare iter int default 0;
set numlen = char_length(modnumber);
while iter < numlen do
set iter = iter + 1;
if mod(iter,2) = 0 then
set sumeven = sumeven + smallint(substr(char(modnumber),
numlen - iter + 1,1));
else
set sumodd = sumodd + smallint(substr(char(modnumber),
numlen - iter + 1,1));
end if;
end while;
set sumodd = sumodd * 3;
set sumeven = sumeven + sumodd;
return smallint(case mod(sumeven,10)
when 0 then 0
else 10 - mod(sumeven,10) end);
end;