|
将整数转换成数字字母编号
- declare @tstarttime datetime=getdate();
- PRINT dbo.fnpbCharCalc_NextChar('0123456789ABCDEFGHJKLMNPQRSTUWXY','0',8,4123523);
- print 'SQL CLR 函数 spend '+cast(datediff(millisecond,@tstarttime,getdate()) as nvarchar(20))+' ms';
- print '-----';
- select @tstarttime=getdate();
- DECLARE @iIden INT = 4123523, @iLen INT = 8;
- DECLARE @sChar NVARCHAR(200) = '0123456789ABCDEFGHJKLMNPQRSTUWXY';
- DECLARE @iDivide INT=@iIden,@iRemainder INT=0;
- DECLARE @nCharLen INT = LEN(@sChar);
- DECLARE @rtnChar NVARCHAR(200)=0x;
- IF @nCharLen=0 RETURN;
- WHILE (1=1)
- BEGIN
- SELECT @iRemainder=@iDivide%@nCharLen;
- SELECT @iDivide=floor(@iDivide*1.0/@nCharLen);
- SELECT @rtnChar=SUBSTRING(@sChar,@iRemainder+1,1)+@rtnChar;
- IF @iDivide=0 BREAK;
- END;
- PRINT LEFT(REPLACE(SPACE(@iLen),' ','0'), @iLen-LEN(@rtnChar))+@rtnChar;
- print 'SQL 函数 spend '+cast(datediff(millisecond,@tstarttime,getdate()) as nvarchar(20))+' ms';
- print '-----';
复制代码 |
|