title: Working with Trigonometric Functions SQL Server
body: <p>I have a WebApi project with Dapper, and I have the table Products :</p>
  
  <pre><code>[Key]
  public int idProducts { get; set; }
  public string Name { get; set; }
  public float Latitude { get; set; }
  public float Longitude { get; set; }
  public int ProductsItems { get; set; }
  public decimal Price { get; set; }
  </code></pre>
  
  <p>And I need to calculate the distance from point A to B and check if is less then 1km which I already did, but in C#</p>
  
  <pre><code>private static double distance(double lat1, double lon1, double lat2, double lon2, char unit)
      {
          double theta = lon1 - lon2;
          double dist = Math.Sin(deg2rad(lat1)) * 
              Math.Sin(deg2rad(lat2)) +
              Math.Cos(deg2rad(lat1)) * 
              Math.Cos(deg2rad(lat2)) * 
              Math.Cos(deg2rad(theta));
          dist = Math.Acos(dist);
          dist = rad2deg(dist);
          dist = dist * 60 * 1.1515;
          dist = dist * 1.609344;
          return (dist);
      }
      private static double deg2rad(double deg)
      {
          return (deg * Math.PI / 180.0);
      }
      private static double rad2deg(double rad)
      {
          return (rad / Math.PI * 180.0);
      }
  </code></pre>
  
  <p>And <code>bool isLess = distance(-8.157908, -34.931675, -8.164891, -34.919033, 'K') &lt; 1</code></p>
  
  <p>But that way I would have to do <code>select * from Products</code>, get all results <code>AsList()</code> and make a loop to get each item and check if the distance From the A to B is valid and its not Practical! I'm not used to make these kinda of queries with Math Involved.</p>
  
  <p>How to create a query where I could pass the Lat and Long from Point A and make that math and return just a list of valid Items ?</p>