Я столкнулся с проблемой. Я использую функцию CodeTo128B в T-SQL. Проблема, с которой я столкнулся, если я даю ему значение, в котором есть пробелы, а затем передаю результат в отчет SSRS со шрифтом sAdC128c, штрих-код не может быть прочитан (устройства, которые считывают штрих-коды, просто не распознают его, потому что штрих-код на изображении не в такт (между ними есть пробелы)
Я собрал два значения для справки по тестированию
SELECT [dbo].[CodeTo128B] ('1 TEST') AS [Column]
UNION
SELECT [dbo].[CodeTo128B] ('1TEST') AS [Column]
Проблема в том, что первый штрих-код не распознается считывателем (приложение для мобильного телефона Android Сканер штрих-кода, я думаю, это потому, что в штрих-коде есть пробел, но я не могу понять, что не так с этой функцией, почему она не распознают пробелы? Как я вижу, значения ASCII также отличаются из-за пробела (значения столбца)
Любые идеи ? Любая помощь будет очень высоко ценится
ALTER FUNCTION [dbo].[CodeTo128B] (@myString varchar(255))
RETURNS VARCHAR(255) AS
BEGIN
-- Define the string of characters that we'll need to pull the reference of
declare @asciiString varchar(255)
select @asciiString = ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
select @asciiString = @asciiString + char(195) -- 0xC3
select @asciiString = @asciiString + char(196) -- 0xC4
select @asciiString = @asciiString + char(197) -- 0xC5
select @asciiString = @asciiString + char(198) -- 0xC6
select @asciiString = @asciiString + char(199) -- 0xC7
select @asciiString = @asciiString + char(200) -- 0xC8
select @asciiString = @asciiString + char(201) -- 0xC9
select @asciiString = @asciiString + char(202) -- 0xCA
-- Define the stop and start characters
declare @stopchar char(1)
declare @startchar char(1)
declare @spacechar char(1)
select @stopchar = char(206) -- 0xCE
select @startchar = char(204) -- 0xCC
select @spacechar = char(194) -- 0xC2
-- Define the final holding place of our output string
declare @finalArray varchar(255)
-- Define the variables that we'll need to be using
declare @checksumTotal int
declare @checksum int
select @checksumTotal = 104;
select @checksum = 0;
-- Start building our output
select @finalArray = @startchar
-- Loop through our input variable and start pulling out stuff
declare @position int
declare @thisChar char(1)
select @position = 1
while @position <= len(@myString)
begin
select @thisChar = substring(@myString, @position, 1)
select @checksumTotal = @checksumTotal + (@position * (ascii(@thischar)-32))
select @finalArray = @finalArray + @thisChar
select @position = @position + 1
end -- We've gone past the length now
-- Now we need to figure out and add the checksum character
select @checksum = @checksumTotal % 103
if @checksum = 0
select @finalArray = @finalArray + @spacechar
else
-- Barcorde array assumes 0 as initial offset so we need to add 1 to checksum
select @finalArray = @finalArray + substring(@asciiString, @checksum+1, 1)
-- Now we append the stop character
select @finalArray = @finalArray + @stopchar
-- The @final Array represents the barcode encoded string
return @finalArray
END





Решил самостоятельно. Просто переписал функцию, чтобы пересчитывать при передаче пустого значения и заполнять пустое место в сформированной строке
Ссылка на код отображается ниже Удачного кодирования :)
CREATE FUNCTION [dbo].[CodeTo128B]
(
@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)
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 = (@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
SET @encoded_string = replace(@v_data_to_encode,' ',char(194))
return CONCAT (@start_character,@encoded_string,@check_digit_char,@stop_character)
end