T-SQL UDF Function: Generate Barcode — Code 128B ( Function 2)





ALTER FUNCTION [dbo].[CodeTo128B] (@stringToEncode VARCHAR(19))
RETURNS VARCHAR(19) AS
BEGIN

   DECLARE @encodedString AS VARCHAR(19) =''           
   
  IF LEN(@stringToEncode) > 0
   BEGIN

;with mycte as (
select  (104+SUM(n *(ascii(SUBSTRING(@stringToEncode, n, 1)) -32)))%103  as checkSum1
from (Values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20)) d(n) 
)

Select  @encodedString=CHAR(204)+@stringToEncode+ CHAR(checkSum1 + CASE WHEN checkSum1< 95 THEN 32 ELSE 100 END)+ CHAR(206) 
FROM mycte

 RETURN @encodedString
END
   
   RETURN ''
END


 

The font download:

http://www.dafont.com/code-128.font

Edit:
Try another download font:
http://www.jtbarton.com/Barcodes/Code128.aspx#OriginalFreeCode128

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s