title: SQL Server distance search
body: <p>I have a Microsoft SQL Server database with a table of Locations. Each location has its address and latitude and longitude coordinates.</p>
  
  <p>In my application, the user can input a zipcode and we return a list of close by locations.
  This is my approach.
  a) Using a zipcode DB I search the lat,lon for the zipcode (this is the center point).
  b) I run a search like this </p>
  
  <pre><code>SELECT Position_ID, distance(pos_lon,pos_lat,zip_lon,zip_lat) dist 
  FROM Positions
  ORDER BY dist
  </code></pre>
  
  <p>"distance" is a function that calculates the distance between two points.</p>
  
  <p>The problem is that as my location DB increases the time to run these searches is starting to grow.</p>
  
  <p>Is there a better approach?</p>