SQLに投稿されたコード一覧

SQL Google Chart Encoding

-- T-SQL --
set nocount on

-- Declares the parameters
declare @VALUE int
declare @ENCODE varchar(64)
declare @DIVISOR int
declare @DIVISION_NUMBER int
declare @COUNTER int

-- ---------------------------
-- CONFIGURABLE SETTINGS:START
-- ---------------------------

-- Defines the numbers which you want to encode
set @VALUE = 100

-- Supported encoding characters
set @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 parameters
    set @DIVISOR = @VALUE - (len(@ENCODE) * len(@ENCODE) - 1)
    set @DIVISION_NUMBER = 1
    set @COUNTER = 0

    -- Loops
    while (len(@DIVISOR) - 3) > @COUNTER
    begin
        -- Defines the parameters
        set @DIVISION_NUMBER = @DIVISION_NUMBER * 10
        set @COUNTER = @COUNTER + 1
    end

    -- Defines the values
    set @VALUE = @VALUE / @DIVISION_NUMBER

    -- Retrieves the encoding characters
    select right(left(@ENCODE, @VALUE / len(@ENCODE) + 1), 1) + right(left(@ENCODE, @VALUE % len(@ENCODE) + 1), 1), @DIVISION_NUMBER
end
else
begin
    -- Simple Encoding --
    -- Retrieves the encoding characters
    select right(left(@ENCODE, @VALUE / len(@ENCODE) + 1), 1) + right(left(@ENCODE, @VALUE % len(@ENCODE) + 1), 1)
end

よく投稿されているコード

タグ

最近投稿されたコード