Yes. Even if the points are all in Southern California. You will still have the problem.
There are ways to improve the problem. Bascially, your algorithm will prefer matches that are due North, south, east or west of the given search. By using the sqrt function, all directions, including NW, SW, SE, and NE will all have an equal playing ground.
That being said, there are ways to improve the situation. Mostly, this method will require a lot of extra coding, but will speed up the calculations. Here's the general idea.
First start off searching a relatively small area. Let's say +- .1 degree latitude by +- .1 degree longitude.
Like this...
Code:
Select *
From dbo_TblContract
Where sqrt((Latitude - @Lat) * (Latitude - @Lat) + (Longitude-@Lon) * (Longitude - @Lon)) =
(
Select Min(sqrt((Latitude - @Lat) * (Latitude - @Lat) + (Longitude-@Lon) * (Longitude - @Lon)))
From dbo_TblContract
Where Latitude > @Lat - [!].1[/!]
And Latitude < @Lat + [!].1[/!]
And Longitude > @Lon -[!].1[/!]
And Longitude < @Lon + [!].1[/!]
)
And Latitude > @Lat - [!].1[/!]
And Latitude < @Lat + [!].1[/!]
And Longitude > @Lon -[!].1[/!]
And Longitude < @Lon + [!].1[/!]
If this still takes a long time, then maybe try 0.5 instead. The problem with this approach is that you may not get any matches because all of matches are too far away. So, you'll need to code this such that if no points are returned, you increase the size of the search distance ([!].1[/!]).
You will also want to make sure you have an index on your table that includes latitude and longitude. With Access, I'm not sure how to do that, but I'm sure it won't be that hard to find either.
So... sure... it'll take extra coding, but the performance increase will be well worth it.
-George
Strong and bitter words indicate a weak cause. - Fortune cookie wisdom