TIA
Assuming that "@barcode" is a string containing the digits of a UPC-A
barcode, this should do:
SELECT @checkdigit = (
10 - (
(
CONVERT(INT, SUBSTRING(@barcode, 1, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 3, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 5, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 7, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 9, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 11, 1))
) * 3 + (
CONVERT(INT, SUBSTRING(@barcode, 2, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 4, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 6, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 8, 1)) +
CONVERT(INT, SUBSTRING(@barcode, 10, 1))
)
) % 10
) % 10;
--
J.
"Jeroen Mostert" <jmos...@xs4all.nl> wrote in message
news:4ae20027$0$83243$e4fe...@news.xs4all.nl...
If you mean producing a barcode *image*, that's not something you want to do
in SQL even if you can (in theory). Use client code and one of the many
available software packages for that.
If you mean producing barcode digits from a string, there is no single
uniform way to do that. UPC is a digit-only barcode, you cannot use it to
represent strings unless you already have a specific mapping between strings
and digits in mind. There are barcodes that can represent strings (like Code
128) but those do not use digits as such, just different barcode widths.
--
J.
"Jeroen Mostert" <jmos...@xs4all.nl> wrote in message
news:4ae208e0$0$83236$e4fe...@news.xs4all.nl...
--
J.