Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.7.0+

QR Code Numeric, Alphanumeric and Byte Modes

See more QR Code Examples

Demonstrates the QR encoding modes. Digits alone are stored in numeric mode, and text made only of digits, upper-case letters, space and $ % * + - . / : in alphanumeric mode. Both pack more characters into a symbol than byte mode, which is used for everything else. QrCode chooses the most compact mode the text allows, and the response reports it. A product code written in upper case therefore gives a smaller symbol than the same code in lower case.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  This example requires the Chilkat API to have been previously unlocked.
    --  See Global Unlock Sample for sample code.

    DECLARE @fmt int
    EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    DECLARE @jsonOut int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT

    --  Digits only.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', '00123456789012345678'
    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.mode'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'digits: mode ' + @sTmp0 + ', version ' + @iTmp0

    --  Upper-case letters, digits, space and - are all in the alphanumeric set.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'ORDER-12345 LOT A7 SHELF 12-C'
    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.mode'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'upper case: mode ' + @sTmp0 + ', version ' + @iTmp0

    --  Lower-case letters are not, so the same text in lower case needs byte mode.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'order-12345 lot a7 shelf 12-c'
    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.mode'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'lower case: mode ' + @sTmp0 + ', version ' + @iTmp0

    --  The mode can be named.  Byte mode can hold any text.  Naming a mode the text cannot use
    --  (numeric for text with letters, for example) fails with conflictingOptions.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', '00123456789012345678'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'encoding.qr.mode', 'byte'
    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.mode'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'digits as bytes: mode ' + @sTmp0 + ', version ' + @iTmp0

    --  The four symbols, in the order they were made:

    --  image

    --  Sample output:

    --  digits: mode numeric, version 1
    --  upper case: mode alphanumeric, version 2
    --  lower case: mode byte, version 3
    --  digits as bytes: mode byte, version 2

    EXEC @hr = sp_OADestroy @fmt
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @jsonOut


END
GO