参考博文:http://www.cnblogs.com/wghao/p/6381865.html
实现了N进制转换的过程:
过程代码如下:
/*
declare @outres varchar(1024)
exec T10TOTN 110,@outres output,11
select @outres
*/
alter procedure T10TOTN(
@input_int int,
@output varchar(1024) output,
@N_int int
)
as
begin
set @output = ''
if 1 < @N_int and @N_int <= 10 begin
while(1=1) begin
select @output = convert(varchar(1024), @input_int%@N_int) + @output, @input_int = @input_int/@N_int;
if @input_int = 0 break;
end;
return;
end
if @N_int > 10 and @N_int <36 begin
declare @tb_tmp as table(id int identity(0,1) primary key,radix char(1))
;with cte as (select top (@N_int) row_number() over(order by getdate())-1 as id from sys.columns)
insert into @tb_tmp(radix)
select case when id>9 then char(55+id) else rtrim(id) end as radix from cte where char(55+id) not in ('I','O','U')
while(1=1) begin
select @output = convert(varchar(1024),(select radix from @tb_tmp where id = @input_int%@N_int)) + @output, @input_int = @input_int/@N_int;
if @input_int = 0 break;
end;
return;
return;
end
return;
end