SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Barcode font 128b -SQL function


Barcode font 128b -SQL function

Author
Message
Eliza
Eliza
Valued Member
Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)

Group: General Forum Members
Points: 69 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
mister.magoo
mister.magoo
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4094 Visits: 7865
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


select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • frisko
    frisko
    Forum Newbie
    Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

    Group: General Forum Members
    Points: 7 Visits: 0
    Thanks mister.magoo, this works for me!
    mister.magoo
    mister.magoo
    SSCarpal Tunnel
    SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

    Group: General Forum Members
    Points: 4094 Visits: 7865
    frisko (4/11/2014)
    Thanks mister.magoo, this works for me!


    You are most welcome - glad it is of use.

    MM


    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • patilyatin542
    patilyatin542
    Grasshopper
    Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

    Group: General Forum Members
    Points: 14 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!!! Crying
    mister.magoo
    mister.magoo
    SSCarpal Tunnel
    SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

    Group: General Forum Members
    Points: 4094 Visits: 7865
    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!!! Crying


    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 :-D

    MM


    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • patilyatin542
    patilyatin542
    Grasshopper
    Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

    Group: General Forum Members
    Points: 14 Visits: 5
    thanks M.M for reverting back!!!
    please upload the updated code, you are saying. Sad
    mister.magoo
    mister.magoo
    SSCarpal Tunnel
    SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

    Group: General Forum Members
    Points: 4094 Visits: 7865
    patilyatin542 (10/2/2014)
    thanks M.M for reverting back!!!
    please upload the updated code, you are saying. Sad


    I already changed the code.

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

    MM


    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • patilyatin542
    patilyatin542
    Grasshopper
    Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

    Group: General Forum Members
    Points: 14 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!!!

    Unsure
    mister.magoo
    mister.magoo
    SSCarpal Tunnel
    SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

    Group: General Forum Members
    Points: 4094 Visits: 7865
    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!!!

    Unsure


    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


    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • Attachments
    Code128_SSRS.PNG (731 views, 6.00 KB)
    Go


    Permissions

    You can't post new topics.
    You can't post topic replies.
    You can't post new polls.
    You can't post replies to polls.
    You can't edit your own topics.
    You can't delete your own topics.
    You can't edit other topics.
    You can't delete other topics.
    You can't edit your own posts.
    You can't edit other posts.
    You can't delete your own posts.
    You can't delete other posts.
    You can't post events.
    You can't edit your own events.
    You can't edit other events.
    You can't delete your own events.
    You can't delete other events.
    You can't send private messages.
    You can't send emails.
    You can read topics.
    You can't vote in polls.
    You can't upload attachments.
    You can download attachments.
    You can't post HTML code.
    You can't edit HTML code.
    You can't post IFCode.
    You can't post JavaScript.
    You can post emoticons.
    You can't post or upload images.

    Select a forum

































































































































































    SQLServerCentral


    Search