Guys,

I am working on trying to figure out country from which ip originated. This can be done using ip number and a dataset (which is availiable on the web for free).

I written a MS SQL 2005 function which will transform ip address to ip number. Problem is performance.

My query looks like this

select top 10
personId, t.*
from
person
left outer join ipToCountry t on cast(t.ipLower as bigint)<=ipToIpNumber(ipaddress) and cast(t.ipUpper as bigint)>=pToIpNumber(ipaddress)

It takes ages to run and the server is pretty beefy. Any suggestions? How I could make it quicker?

Thanks.