Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Barcode font 128b -SQL function Expand / Collapse
Author
Message
Posted Saturday, July 06, 2013 6:06 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, February 09, 2014 8:54 AM
Points: 32, Visits: 77
Hi,

I am looking for an SQL function that will generate the correct characters to make barcode font code128 work when used in Microsoft Word. The data is passed to word with the data tag using the barcode font.

This is a web link to the rules and where the font can be downloaded.


http://grandzebu.net/informatique/codbar-en/code128.htm

A bit more info on the font here

http://en.wikipedia.org/wiki/Code_128

And I tried
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=70901
http://www.sqlservercentral.com/Forums/Topic1065554-149-1.aspx
http://www.sqlservercentral.com/Forums/Topic1062489-1291-1.aspx

But none of these solutions appear to work when tested with a barcode reader. The bar code reader does work because we tested it against web sites generating the barcodes and it is code128b we are working with

Anyone any ideas/SQL functions that do work.
Many thanks
Eliza
Post #1470917
Posted Saturday, July 06, 2013 7:23 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 12:00 AM
Points: 1,659, Visits: 5,220
You could try this, it produces the right output for me...

create function Code128Barcode(@input varchar(3997), @table char(1) = 'B')
returns table
with schemabinding
as
--=======================================================================--
--== Function to build the required data string for a code 128 barcode ==--
--== Code written from a description of the specification by ==--
--== Mister Magoo - find me on SSC or twitter @mistermag00 ==--
--== NOTE: this code does not validate that you are passing in valid ==--
--== data for code 128 barcodes. SISO ==--
--=======================================================================--

return (
-- build an inline fast tally table
with n10(n) as (
select 1 union all select 1 union all
select 1 union all select 1 union all
select 1 union all select 1 union all
select 1 union all select 1 union all
select 1 union all select 1
),
n100(n) as (
select 1 from n10 a, n10 b
),
n10000(n) as (
select 1 from n100 a, n100 b
),
tally(n) as (
-- limit the tally table to the exact length of the input string
select top(len(@input)) row_number() over(order by @@spid) as n from n10000 order by n
)

-- Now the query that does the "work"
select
-- in Code 128, the "table" is denoted by one of three START codes
case @table
when 'A' then char(208)
when 'B' then char(209)
when 'C' then char(210)
end -- START

+ @input -- Original string

-- The code 128 Checksum is made up by taking the sum of each
-- of the input string's characters numbers (ASCII - 32)
-- multiplied by it's position in the string , plus the character
-- number of the START character, then taking MODULUS 103
-- This number is converted to ASCII by adding 32

+ char(32+(sum(n*(ascii(substring(@input,n,1))-32))+case @table when 'A' then 103 when 'B' then 104 when 'C' then 105 end)%103)

-- The STOP character never changes and denotes the end of the barcode.

+ CHAR(211) -- STOP

-- we need an alias for the column
AS encoded_for_128
from tally
)

edit:increased number of rows in the inline tally


MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1470956
    Posted Friday, April 11, 2014 3:35 AM
    Forum Newbie

    Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

    Group: General Forum Members
    Last Login: Friday, April 11, 2014 3:34 AM
    Points: 1, Visits: 0
    Thanks mister.magoo, this works for me!
    Post #1560778
    Posted Friday, April 11, 2014 5:40 AM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 12:00 AM
    Points: 1,659, Visits: 5,220
    frisko (4/11/2014)
    Thanks mister.magoo, this works for me!


    You are most welcome - glad it is of use.


    MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1560835
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse