环思产品论坛

标题: 将整数转换成数字字母编号 [打印本页]

作者: zhouf    时间: 2016-6-8 09:46
标题: 将整数转换成数字字母编号
将整数转换成数字字母编号

  1. declare @tstarttime datetime=getdate();
  2.         PRINT dbo.fnpbCharCalc_NextChar('0123456789ABCDEFGHJKLMNPQRSTUWXY','0',8,4123523);
  3. print 'SQL CLR 函数 spend '+cast(datediff(millisecond,@tstarttime,getdate()) as nvarchar(20))+' ms';
  4. print '-----';
  5. select @tstarttime=getdate();
  6.         DECLARE @iIden INT = 4123523, @iLen INT = 8;
  7.         DECLARE @sChar NVARCHAR(200) = '0123456789ABCDEFGHJKLMNPQRSTUWXY';
  8.         DECLARE @iDivide INT=@iIden,@iRemainder INT=0;
  9.         DECLARE @nCharLen INT = LEN(@sChar);
  10.         DECLARE @rtnChar NVARCHAR(200)=0x;
  11.         IF @nCharLen=0 RETURN;
  12.         WHILE (1=1)
  13.         BEGIN
  14.           SELECT @iRemainder=@iDivide%@nCharLen;
  15.           SELECT @iDivide=floor(@iDivide*1.0/@nCharLen);
  16.           SELECT @rtnChar=SUBSTRING(@sChar,@iRemainder+1,1)+@rtnChar;
  17.           IF @iDivide=0 BREAK;
  18.         END;
  19.         PRINT LEFT(REPLACE(SPACE(@iLen),' ','0'), @iLen-LEN(@rtnChar))+@rtnChar;
  20. print 'SQL 函数 spend '+cast(datediff(millisecond,@tstarttime,getdate()) as nvarchar(20))+' ms';
  21. print '-----';
复制代码





欢迎光临 环思产品论坛 (http://bbs.huansi.cn/) Powered by Discuz! X3.2