--函数
function F_HEXtoDIX(@hex varchar(8))
returns bigint
as
begin
declare @string varchar(16)
declare @pos bigint
declare @return bigint
set @pos=1
set @return=0
set @string='0123456789ABCDEF'
while @pos!>len(@hex)
begin
if substring(reverse(@hex),@pos,1) NOT in ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F')
begin
return null
end
set @return=@return+(charindex(substring(reverse(@hex),@pos,1),@string)-1)*power(16,(@pos-1))
set @pos=@pos+1
end
return @return
end
go
--测试
select dbo.F_hextodix('FF')
/*
255
*/