Three T-SQL Approaches to Distance Matching
Finding the Closest Store: Three T-SQL Approaches to Distance Matching Three ways to match people to their nearest store in T-SQL — great-circle distance from latitude/longitude, arithmetic ZIP code matching when you have no coordinates at all, and a Pythagorean approximation compared against the trigonometric method. Same sample data, three techniques, one decision framework for picking the right one. Published · Tags: SQL, T-SQL, Mapping, Geolocation, Distance Calculation, Pythagorean Theorem, Latitude and Longitude, ZIP Codes, Nearest Store Matching "Which store is closest to this person?" sounds like a simple question, but the right T-SQL answer depends entirely on what data you actually have. If you're lucky enough to have latitude and longitude for both people and stores, the problem is straightforward geometry. If all you have is a five-digit ZIP code, you need a different strategy — one that degrades gracefully as your address data gets less precise. And i...