declare @myString varchar(255)select @myString = 'BarCode 1'-- Define the string of characters that we'll need to pull the reference ofdeclare @asciiString varchar(255)select @asciiString = ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'select @asciiString = @asciiString + char(195) -- 0xC3select @asciiString = @asciiString + char(196) -- 0xC4select @asciiString = @asciiString + char(197) -- 0xC5select @asciiString = @asciiString + char(198) -- 0xC6select @asciiString = @asciiString + char(199) -- 0xC7select @asciiString = @asciiString + char(200) -- 0xC8select @asciiString = @asciiString + char(201) -- 0xC9select @asciiString = @asciiString + char(202) -- 0xCA-- Define the stop and start charactersdeclare @stopchar char(1)declare @startchar char(1)declare @spacechar char(1)select @stopchar = char(206) -- 0xCEselect @startchar = char(204) -- 0xCCselect @spacechar = char(194) -- 0xC2-- Define the final holding place of our output stringdeclare @finalArray varchar(255)-- Define the variables that we'll need to be usingdeclare @checksumTotal intdeclare @checksum intselect @checksumTotal = 104;select @checksum = 0;-- Start building our outputselect @finalArray = @startchar-- Loop through our input variable and start pulling out stuffdeclare @position intdeclare @thisChar char(1)select @position = 1while @position <= len(@myString)begin select @thisChar = substring(@myString, @position, 1) select @checksumTotal = @checksumTotal + (@position * (ascii(@thischar)-32)) select @finalArray = @finalArray + @thisChar select @position = @position + 1end -- We've gone past the length now-- Now we need to figure out and add the checksum characterselect @checksum = @checksumTotal % 103if @checksum = 0 select @finalArray = @finalArray + @spacecharelse -- 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 characterselect @finalArray = @finalArray + @stopchar-- The @final Array represents the barcode encoded stringselect @finalArray