function base n
/****** Object: UserDefinedFunction [dbo].[F_NUMERIC_TO_BASE_N] Script Date: 5/29/2018 6:07:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[F_NUMERIC_TO_BASE_N]
(
@Number numeric(32,0),
@Base int
)
returns varchar(110)
as
/*
Function: F_NUMERIC_TO_BASE_N
Function F_NUMERIC_TO_BASE_N converts a numeric(32,0) value, @Number,
to a string of digits in number base @Base,
where @Base is between 2 and 36.
Output digits greater than 9 are represented by
uppercase letters A through Z, where A = 10 through Z = 35.
If input parameter @Number is negative, the output string
will have a minus sign in the leftmost position.
Any non-null numeric(32,0) value for parameter @Number is valid:
-99999999999999999999999999999999 through
99999999999999999999999999999999.
If input parameters @Number or @Base are null,
or @Base is not between 2 and 36,
then the function returns a null value.
*/
begin
declare @Work_Number numeric(38,0)
declare @Modulus int
declare @Digits varchar(36)
declare @Output_String varchar(110)
if @Number is null or @Base is null or @Base < 2 or @Base > 36
begin
return null
end
set @Digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
set @Output_String = ''
set @Work_Number = @Number
while 1=1
begin
Set @Modulus = convert(int,abs(@Work_Number-(round(@Work_Number/@Base,0,1)*@Base)))
set @Output_String = substring(@Digits,@Modulus+1,1) + @Output_String
set @Work_Number = round(@Work_Number/@Base,0,1)
if @Work_Number = 0 break
end -- end while
if @Number < 0 set @Output_String = '-'+@Output_String
return @Output_String
end
GO
declare @times bigint = 1
declare @top_count bigint = 1000
select dbo.[F_NUMERIC_TO_BASE_N](@times * 100000000 + rn * 1000 , 32)
from
(
select top (@top_count) row_number() over (order by (select 1)) rn
from sysobjects a
cross join sysobjects b
cross join sysobjects c
) a