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

Generating a Bar Code

By Masar Ivica,

Sometimes you have to start from beginning, almost from a DOS, especially if you task sounds like "make a simple barcode generator". Naturally, I started with most complicated ideas, to make a RTF (it is not short for read the f*** manual) or a PDF as an add-on to previous article. Other ideas were to create HTML tables with cells black & white backgrounds, or to use GIFs but it is almost complicated like drawing shapes in RTFs or PDFs. But first of all..

Why barcode? We are working with Documentum, so electronic documents are our objects. When you have batch scanning there is need to connect images with attributes in databases. If you have scanning tool you can scan papers into the electronic format but there has to be some link to other data and that it is barcode. Just paste some label with barcode on paper and after scanning use some tool like JavaOCR for OCRing and you can even index documents. Barcode is very good for OCRing. This example does not need barcode reader, but if you want to manage you CD/DVD collection you will need barcode reader like they do in the shops.

And now some technical stuff. Testing environment is: Win 2k, MS SQL server 2000, IE 6.

There is a sql script with one created table psoBarCode39, two functions (hex, checksum39 - for control digit) and main procedure psoCode39. The procedure will produce html file on C disk (C:\PsoCode39.htm).IE is needed for penning because Microsoft font embedding technology is used. Sometimes I get numbers instead of barcode so it is recommended to test results in print preview window. Produced barcode is Barcode 39. Allowed characters are :'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.(space)$/+%'.

Download SQL code.

Hope you are familiar with next syntax from SQL BOL.

Create HTML page with Barcode39.

psoCode39 [@tablex=]tablex,

Is the number of columns int, with no default,
Is the number of rows int, with no default,
Is the number of pages int(visible only in print preview window), with no default,
Is the height of rows int, with no default.
Is the size of barcode int, with no default.
Is the size of text description bellow barcode int, with no default.
0 means no text description.
Is the text in front of barcode varchar(10), with no default.
'' means no prefix,
Is the number with starting value for auto generate barcode with step 1,
0 means take values from table psoBarCode39, int, with no default.
If 1 check digit is added at end of barcode,
other means no check digit int, with no default.


Created Barcode

EXEC psoCode39 3,3,1,70,60,10,'',1000000,0
1000000 1000001 1000002
1000003 1000004 1000005
1000006 1000007 1000008
auto generated barcode

EXEC psoCode39 2,2,1,70,60,10,'',1000000,1
10000001 10000012
10000023 10000034
with check digit

EXEC psoCode39 2,1,1,70,60,10,'PSO',1000000,1
PSO1000000Z PSO1000001-
with prefix

EXEC psoCode39 2,1,1,70,60,10,'',0,1
your data

EXEC psoCode39 2,1,1,70,60,10,'PSO',10,1
EXEC psoCode39 4,10,2,70,60,10,'PSO',10,1

Some additional settings could be done with IE menu File- Page setup. Delete anything from header and footer. Update margins as needed. Be careful with function invocation in the main procedure.

See Also my previous article on creating PDFs.



Total article views: 10781 | Views in the last 30 days: 5
Related Articles

SQL Server Barcodes

You may never need to work with them, but if you do then you will quickly realize how complicated ba...


Using PCL in Stored Procedure for Barcode

Having trouble printing a readable 3 of 9 barcode


Printing barcode using Reporting Services

start and stop chars display OUTSIDE the barcode


Format File 9.0 Prefix Length

How can I default prefix length to 0 for fixed width format file


Barcodes Code128 generator function

Searching for a barcode Code128 generator function

advanced querying