------ Convert decimal to eighteen bytes
Create Function f_int18 (@ num INT)
Returns nvarchar (50)
As
Begin
If @ num = 0
Return '0'
Declare @ s nvarchar (50)
Set @ s =''
While @ num> 0
Select @ s = substring ('0123456789abcdefhg ', @ num % 18 + 1, 1) + @ s, @ num = @ num/18
Return @ s
End
Go
---------- Eighteen bytes to decimal
Create Function f_int10 (@ s nvarchar (50 ))
Returns int
As
Begin
Declare @ I int, @ S2 nvarchar (2), @ num int
Select @ I = Len (@ s), @ num = 0
While @ I> 0
Select @ S2 = substring (reverse (@ s), @ I, 1 ),
@ Num = power (18, @ i-1) * (charindex (@ S2, '0123456789abcdefhg ')-1) + @ num,
@ I = @ I-1
Return @ num
End
Go
Select DBO. f_int18 (9999)
Select DBO. f_int10 ('1cf9 ')
/**//*
--------------------------------------------------
1cf9
(The number of affected rows is 1)
-----------
9999
(The number of affected rows is 1)
*/