how to encode int with base32 in sql server 2008

2019-08-08 02:49发布

i am looking to encode an INT to BASE32 string in SQL Server 2008.

Any suggestions of built-in function or perhaps a custom function?

Thanks

3条回答
够拽才男人
2楼-- · 2019-08-08 03:08

Pretty sure this will need some debugging but should be close. I translated from a c# function I found that converts base10 to base32.

CREATE FUNCTION dbo.Base10toBase32 (@pInput int)
RETURNS varchar(100)
AS
BEGIN
    Declare @pSet char(32)
    Declare @pRslt varchar(100)
    Declare @pRmdr int
    Declare @pPos int

    SET @pSet = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
    SET @pPos = @pInput

    WHILE @pPos > 0
    BEGIN
        SET @pRmdr = @pPos % 32
        SET @pPos = @pPos / 32
        SET @pRslt = SubString(@pSet,@pRmdr+1,1) + @pRslt
    END

    RETURN @pRslt
END
查看更多
何必那么认真
4楼-- · 2019-08-08 03:25

If you're looking for human-readable base32, check out Crockford's: http://www.crockford.com/wrmg/base32.html

Looks like a Dell service tag -- avoids confusion between 1 0 I L etc...

查看更多
登录 后发表回答