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 12»»

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

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, July 5, 2014 1:33 PM
Points: 33, Visits: 81
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 6, 2013 7:23 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 4:19 PM
Points: 1,796, Visits: 5,799
You could try this, it produces the right output for me...

create function [dbo].[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(203)
when 'B' then char(204)
when 'C' then char(205)
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(case when (sum(n*(ascii(substring(@input,n,1))-32))+case @table when 'A' then 103 when 'B' then 104 when 'C' then 105 end)%103>94 then 100
else 32
end+(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(206) -- STOP

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

edit:increased number of rows in the inline tally
edit:fixed incorrect markers
edit:fixed high end checksums - properly this time


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 @ 4:19 PM
    Points: 1,796, Visits: 5,799
    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
    Posted Monday, September 29, 2014 2:38 AM
    Forum Newbie

    Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

    Group: General Forum Members
    Last Login: 2 days ago @ 7:47 PM
    Points: 4, Visits: 5
    thanks M.M.
    I have used this code as my sql function, and returning barcode value using this function to SSRS.
    And in rdlc file I am using Code128 as font; but I am getting boxes at the start and at the end of the barcode.
    So, the barcode is not readable from Barcode scanner.
    Please help!!!
    Post #1620714
    Posted Monday, September 29, 2014 5:42 PM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 4:19 PM
    Points: 1,796, Visits: 5,799
    patilyatin542 (9/29/2014)
    thanks M.M.
    I have used this code as my sql function, and returning barcode value using this function to SSRS.
    And in rdlc file I am using Code128 as font; but I am getting boxes at the start and at the end of the barcode.
    So, the barcode is not readable from Barcode scanner.
    Please help!!!


    There was an error in that code - don't know how it got past QC to be honest!

    I have modified the code - should work now


    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 #1621041
    Posted Thursday, October 2, 2014 9:19 AM
    Forum Newbie

    Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

    Group: General Forum Members
    Last Login: 2 days ago @ 7:47 PM
    Points: 4, Visits: 5
    thanks M.M for reverting back!!!
    please upload the updated code, you are saying.
    Post #1621998
    Posted Thursday, October 2, 2014 11:05 AM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 4:19 PM
    Points: 1,796, Visits: 5,799
    patilyatin542 (10/2/2014)
    thanks M.M for reverting back!!!
    please upload the updated code, you are saying.


    I already changed the code.

    http://www.sqlservercentral.com/Forums/FindPost1470956.aspx


    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 #1622056
    Posted Friday, October 10, 2014 7:47 AM
    Forum Newbie

    Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

    Group: General Forum Members
    Last Login: 2 days ago @ 7:47 PM
    Points: 4, Visits: 5
    hi, M.M.
    :: Code 128 ::
    I have used your code in sql which you described in http://www.sqlservercentral.com/Forums/FindPost1470956.aspx
    and returning value of a column like SELECT encoded_for_128 FROM dbo.Code128Barcode('140000009','B') through procedure to winform, and there I am using dataset to fill values using this procedure; and then filling table adapter and all these things. In SSRS, I have set barcode font to "Code 128" & I have set barcode font size to 30pt, well on execution of program I get barcode printed properly; but scanner doesn't scans it. Am I comiting any kind of mistake???
    :: Bar-Code 39 ::
    I also have used this bar-code in my program, in this case I don't have to use sql function; just I have to add "*" at the start and at the end of my value in SSRS, as it indicates barcode value is between those "*". On execution, it prints properly on font size of 20 pt, but doesn't scans. And on using wordpad, I am setting same value, same font size, same font; it prints and scans well.
    Any Idea?? behind these.
    One thing I have noticed is; when using my program to print bar-code, thickness of printed barcode is greater than barcode thickness printed using wordpad., I am attaching images as below:-
    Using Wordpad=>
    http://postimage.org/image/cvdqpchff/
    Using my WinForm project=>
    http://postimage.org/image/tlp4eofuj/
    Plz help!!!

    Post #1624689
    Posted Saturday, October 11, 2014 5:26 PM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 4:19 PM
    Points: 1,796, Visits: 5,799
    patilyatin542 (10/10/2014)
    hi, M.M.
    :: Code 128 ::
    I have used your code in sql which you described in http://www.sqlservercentral.com/Forums/FindPost1470956.aspx
    and returning value of a column like SELECT encoded_for_128 FROM dbo.Code128Barcode('140000009','B') through procedure to winform, and there I am using dataset to fill values using this procedure; and then filling table adapter and all these things. In SSRS, I have set barcode font to "Code 128" & I have set barcode font size to 30pt, well on execution of program I get barcode printed properly; but scanner doesn't scans it. Am I comiting any kind of mistake???
    :: Bar-Code 39 ::
    I also have used this bar-code in my program, in this case I don't have to use sql function; just I have to add "*" at the start and at the end of my value in SSRS, as it indicates barcode value is between those "*". On execution, it prints properly on font size of 20 pt, but doesn't scans. And on using wordpad, I am setting same value, same font size, same font; it prints and scans well.
    Any Idea?? behind these.
    One thing I have noticed is; when using my program to print bar-code, thickness of printed barcode is greater than barcode thickness printed using wordpad., I am attaching images as below:-
    Using Wordpad=>
    http://postimage.org/image/cvdqpchff/
    Using my WinForm project=>
    http://postimage.org/image/tlp4eofuj/
    Plz help!!!



    The barcode printed from your Winforms project seems to be "fuzzy" - I would look at how you are rendering it to the printer - maybe it is being converted to a low resolution bitmap for printing?

    does it look OK on screen? can you scan your Winforms barcode from the screen using a smartphone (they don't mind scanning screens as they don't use lasers)?

    I can certainly scan code 128 barcodes produced in this way in SSRS...



    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 Attachments 
    Code128_SSRS.PNG (129 views, 6.33 KB)
    Post #1624961
    « Prev Topic | Next Topic »

    Add to briefcase 12»»

    Permissions Expand / Collapse