当前位置: 代码迷 >> Sql Server >> 一个关于IP的有关问题
  详细解决方案

一个关于IP的有关问题

热度:65   发布时间:2016-04-27 21:11:24.0
一个关于IP的问题?
IP表里面的字段是这样的:4.36.125.0,我要判断用户的IP是哪个地区的,该如何判断?
顺便问一句,我的表里有30多万条数据,该如何加快查询呢?

------解决方案--------------------
create function iptoNum(@ip varchar(50))
returns bigint
as
begin

declare @s varchar(50)
declare @ip1 varchar(50)
declare @m int
select @s= ' ',@[email protected]+ '. '
while charindex( '. ',@ip)> 0
begin
select @ip1=left(@ip,charindex( '. ',@ip)-1)
set @m=len(@ip1)
while @m <3
begin
set @ip1= '0 '[email protected]
set @[email protected]+1
end
select @[email protected][email protected]
select @ip=stuff(@ip,1,charindex( '. ',@ip), ' ')
end
return convert(bigint,@s)

end

这个我是自己根据请教修改的,你试试看
  相关解决方案