环思产品论坛
标题:
将整数转换成数字字母编号
[打印本页]
作者:
zhouf
时间:
2016-6-8 09:46
标题:
将整数转换成数字字母编号
将整数转换成数字字母编号
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 '-----';
复制代码
欢迎光临 环思产品论坛 (http://bbs.huansi.cn/)
Powered by Discuz! X3.2