This code is encoding to characters from the numbers.
This code is encoding to characters from the numbers.
-- T-SQL --set nocount on-- Declares the parametersdeclare @VALUE intdeclare @ENCODE varchar(64)declare @DIVISOR intdeclare @DIVISION_NUMBER intdeclare @COUNTER int-- ----------------------------- CONFIGURABLE SETTINGS:START-- ----------------------------- Defines the numbers which you want to encodeset @VALUE = 100-- Supported encoding charactersset @ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'-- ----------------------------- CONFIGURABLE SETTINGS:END-- ----------------------------- Defines the format (which should be simple or extended)if @VALUE > (len(@ENCODE) * len(@ENCODE) - 1)begin-- Extended Encoding ---- Defines the parametersset @DIVISOR = @VALUE - (len(@ENCODE) * len(@ENCODE) - 1)set @DIVISION_NUMBER = 1set @COUNTER = 0-- Loopswhile (len(@DIVISOR) - 3) > @COUNTERbegin-- Defines the parametersset @DIVISION_NUMBER = @DIVISION_NUMBER * 10set @COUNTER = @COUNTER + 1end-- Defines the valuesset @VALUE = @VALUE / @DIVISION_NUMBER-- Retrieves the encoding charactersselect right(left(@ENCODE, @VALUE / len(@ENCODE) + 1), 1) + right(left(@ENCODE, @VALUE % len(@ENCODE) + 1), 1), @DIVISION_NUMBERendelsebegin-- Simple Encoding ---- Retrieves the encoding charactersselect right(left(@ENCODE, @VALUE / len(@ENCODE) + 1), 1) + right(left(@ENCODE, @VALUE % len(@ENCODE) + 1), 1)end