十进制转36进制函数(0~9, A~Z)
create function [dbo].ufn_int2str36( @value int) returns varchar(20) as begin -- 转数字为36进制(数字+大写字母)的字符串 -- declare @value int -- set @value = 99999999 DECLARE @radix int set @radix = 36 DECLARE @seq CHAR(36) DECLARE @result VARCHAR(50) DECLARE @digit CHAR(1) -- SET @seq = '0123456789ABCDEF' SET @seq = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' SET @result = SUBSTRING(@seq, (@value%@radix)+1, 1) --求十进制的@value除以的余数,找到余数对应进制的值 WHILE @value > 0 BEGIN SET @digit = SUBSTRING(@seq, ((@value/@radix)%@radix)+1, 1) SET @value = @value/@radix IF @value <> 0 SET @result = @digit + @result END return right( '00000000'+ @result,6) END
标签:radix,进制,seq,36,value,SET,result,十进制 From: https://www.cnblogs.com/easybi/p/17855344.html