Requires Free Membership to View
This should just be basically like the following:
select tab1.* from a tab1 cross join (select lat+1 maxlat,lat-1 minlat,long+1 maxlong,long-1 minlong from a where city = 'somecity') tab2 where tab1.lat between tab2.minlat and tab2.maxlat and tab1.long between tab2.minlong and tab2.maxlongI would also recommend grabbing books by Joe Celko, Itzik Ben-Gan/Tom Moreau and Ken Henderson. All of them have some very good examples of advanced queries and things like this type of proximity query.
For More Information
- Dozens more answers to tough SQL Server questions from Michael Hotek are available here.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- The Best SQL Web Links
- Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL Server questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
This was first published in June 2002

Join the conversationComment
Share
Comments
Results
Contribute to the conversation