SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 BARCODE 128 Encoding
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

druer
Constraint Violating Yak Guru

USA
314 Posts

Posted - 08/23/2006 :  09:36:09  Show Profile  Reply with Quote
The following TSQL code will take a character string and perform the encoding that is necessary to generate a BARCODE 128 formatted string to be used with a BARCODE 128 font.
declare @myString varchar(255)
select @myString = 'BarCode 1'

-- 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
select @finalArray


Hope it helps,
Dalton

Blessings aren't so much a matter of "if they come" but "are you noticing them."

Barcode
Starting Member

11 Posts

Posted - 11/20/2012 :  22:32:03  Show Profile  Reply with Quote
Thanks, this helps me a lot with my barcode project on report solution :P
unspammed
Go to Top of Page

ChickenCanoe
Starting Member

1 Posts

Posted - 11/30/2012 :  15:50:12  Show Profile  Reply with Quote
I believe this method contains an error. The ascii string should be:

select @asciiString = ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
select @asciiString = @asciiString + char(200) -- 0xC8
select @asciiString = @asciiString + char(201) -- 0xC9
select @asciiString = @asciiString + char(202) -- 0xCA
select @asciiString = @asciiString + char(203) -- 0xCB
select @asciiString = @asciiString + char(204) -- 0xCC
select @asciiString = @asciiString + char(205) -- 0xCD
select @asciiString = @asciiString + char(206) -- 0xCE
select @asciiString = @asciiString + char(207) -- 0xCF


As per: http://en.wikipedia.org/wiki/Code_128#Check_digit_calculation
Go to Top of Page

ValentineVic
Starting Member

1 Posts

Posted - 05/31/2013 :  05:43:52  Show Profile  Reply with Quote
The same class SQL Server barcode font encoder that is used to format data for barcode font.
http://www.keepautomation.com/font_tools/sql_reporting_services_barcode_font_encoder.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000