Pretty sure it will require some debugging, but should be close. I translated from the C # function that I found, which 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
source share