Sorry, there was a small bug in step 5 (subtract the result obtained in paragraph 4. by multiple of 10 higher).
The local variable [font="Courier New"]@i[/font] must start from zero and not from one, the step 5 is amended as follows:
[font="Courier New"] /* 5. Subtract the result obtained in paragraph 4) by multiple of 10 higher. */
IF ((@CheckSum % 10) = 0)
BEGIN
-- Check digit equal ZERO
SET @checksum = 0
END
ELSE BEGIN
SET @tmpMulSup = LTRIM(RTRIM(STR(@CheckSum)))
--SET @i = 1
SET @i = 0
WHILE @i <= (LEN(@tmpMulSup) - 1)
BEGIN
SET @Tmp = @Tmp + SUBSTRING(@tmpMulSup, @i, 1)
IF (@i = LEN(@tmpMulSup) - 1)
BEGIN
SET @Tmp = LTRIM(RTRIM(STR(CAST(@tmp AS INTEGER) + 1)))
END
SET @i = (@i + 1)
END
SET @checksum = CAST(@tmp AS INTEGER) - @checksum
END[/font]
Now, the check digit for a code UCC/EAN '0000000001111' is 2 🙂
Thanks for your message!
Bye