create function ip2number (@ip varchar(16))returns bigint
as
begin
set @ip=@ip+'.'
declare @pos tinyint
declare @num bigint
declare @bin int,@off int
set @bin=16777216
set @off=0
set @num=0
while @bin>=1
begin
set @pos=@off+1
set @off=charindex('.',@ip,@pos)
set @num=@num+convert(int,substring(@ip,@pos,@off-@pos))*@bin
set @bin=@bin/256
end
return @num
end
go