用到了之前的数字转换为16进制数函数 IntToHex
create function [dbo].[IntToHex](@num int)
returns varchar(100)
as
begin
declare @re varchar(100)
set @re=''
while @num>0
select @re=substring('0123456789ABCDEF',@num%16+1,1)+@re
,@num=@num/16
return(@re)
end
create function [dbo].[GetUserCode](@word varchar(256))
RETURNS VARCHAR(512)ASBEGIN
DECLARE @key varchar(256)--密钥
SET @key='drsf45fwq'
DECLARE @return varchar(256)--返回值
DECLARE @i int,@j int,@temp int
SELECT
@i=1,@j=1,@return=''
WHILE(@i<=len(@word))
BEGIN
SET
@return=@return+dbo.IntToHex(ascii(substring(@word,@i,1))+ascii(substring(@key,@j,1))%256)
--SELECT @temp,@i,@j
IF(@j<len(@key)) SET
@j=@j+1
ELSE SET @j=1
SET @i=@i+1
END
RETURN @returnEND