文件名称:IMEI校验码计算
文件大小:1KB
文件格式:TXT
更新时间:2017-11-24 11:28:18
IMEI校验码
/* 返加IMEI校验码 */ CREATE FUNCTION FnIMEICheck(@value nvarchar(14)) RETURNS VARCHAR(15) AS BEGIN declare @result nvarchar(15) declare @len int declare @n int declare @sum1 int declare @sum2 int declare @sum int declare @sSum nvarchar(10) select @len=len(@value) select @n = 1 select @sum1=0 select @sum2=0 select @sum=0 while @n<=@len begin if (@n%2=0) begin select @sum2=convert(int,substring(@value,@n,1))*2 if(@sum2<10) select @sum=@sum+@sum2 else begin select @sum=@sum+convert(int,substring(convert(nvarchar(2),@sum2),1,1))+convert(int,substring(convert(nvarchar(2),@sum2),2,1)) end end else begin select @sum1=convert(int,substring(@value,@n,1)) select @sum=@sum+@sum1 end select @n=@n+1 end select @sSum=convert(nvarchar(10),@sum) if (substring(@sSum,len(@sSum),1)='0') select @result = '0' else select @result = convert(nvarchar(1),10-convert(int,substring(@sSum,len(@sSum),1))) RETURN @value+@result END