September 18, 2017 at 2:59 am
Use Following Functions
ALTER FUNCTION [dbo].[CreateBarcodeCode128]
(
@Barcode VARCHAR(20)
)
RETURNS VARCHAR(20)
BEGIN
DECLARE @site_value INT;
SET @site_value =1;
DECLARE @v_data_to_encode varchar(4000)
DECLARE @check_digit_char varchar(1)
DECLARE @check_digit BIGINT
DECLARE @start_character varchar(1)
DECLARE @stop_character varchar(1)
DECLARE @current_value bigint
DECLARE @encoded_string varchar(1000)
DECLARE @weight_total BIGINT
DECLARE @mrLen BIGINT
SET @v_data_to_encode = UPPER(@Barcode)
-- Calcuation variables
SET @start_character = CHAR(0203)
SET @stop_character = CHAR(0206)
SET @weight_total = ASCII(@start_character) - 100
SET @mrLen = LEN(@v_data_to_encode)
WHILE @site_value <= @mrLen
BEGIN
SET @current_value = CAST(ASCII(SUBSTRING (@v_data_to_encode, @site_value, 1)) AS BIGINT)
if @current_value < 135
set @current_value = @current_value - 32
ELSE if @current_value >= 135
set @current_value = @current_value - 100
SET @current_value = @current_value * @site_value
SET @weight_total = @weight_total + @current_value
set @site_value = @site_value+1
END
--SET @check_digit = mod(@weight_total,103)
SET @check_digit = (@weight_total % 103)
BEGIN
if @check_digit < 95 and @check_digit > 0
SET @check_digit_char = CHAR(@check_digit + 32)
ELSE if @check_digit >= 95
SET @check_digit_char = char(@check_digit + 100)
ELSE if @check_digit = 0
SET @check_digit_char = char(194);
END
-- check digit determined
-- Replace any occurence of ' ' (space) with chr(194)
SET @encoded_string = replace(@v_data_to_encode,' ',char(194))
return CONCAT (@start_character,@encoded_string,@check_digit_char,@stop_character)
end
September 18, 2017 at 6:39 am
OK, but what is your question?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 22, 2017 at 7:48 pm
I don't think there is one. Just someone sharing code that might save you half a day.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply