/ * ================================================================================================================================================================ ======== Procedure: USP_CONVERTINTTO DESCRIPTION: Convert a Number to 1 ~ 36 Creation Date: 2005-4-25 author: frank xie ================== ====================================== =================== ============================================== xi ====== Rev Date Description = ============================================================================================================================================================================================================= ===== 1 2005-4-25 generated by FRANK XIE =================================== ===================== Declare @dd varchar (50) Exec USP_CONVERTINTTO 55, 36, @ DD OUTPUTPRINT @ DD * /
Create Procedure USP_CONVERTINTTTTTO (@ANumber int = 0, - 10 Enter number @ConvertType INT = 10, - Required Creation @Result Varchar (50) Output - Return to the value after the changed value) AS BEGIN DECLARE @List VARCHAR (36) DECLARE @yushu INT DECLARE @shang INTIF @convertType> 36 BEGIN RAISERROR ( '@convertType must less then 36', 16, 1) return -1 END ELSE BEGIN IF @convertType <1 BEGIN RAISERROR ( '@ConvertType Must Lager Then 1', 16, 1) Return -1 End End IF @Result Is Null Set @Result = ''
Set @List = '123456789abcdefghijklmnopqrstuvwxyz'
Set @YUSHU = @ANumber% @convertType
IF @YUSHU> 0 set @Result = substring (@ list, @ Yushu, 1) @Result else begin if @Result <> '0' set @Result = '0' @Result End
Set @Shang = @anumber / @converttype
IF @Shang> = @converttype begin declare @res int exec @res = usp_convertintto @ Shang, @ ConvertType, @ Result Output
IF @res = -1 return -1 end else set @Result = Substring (@ list, @ shang, 1) @Result
Return 0nd