Just like @TimBiegeleisen and @RobertRodkey have said, it's an old school formula for calculating the distance between two points on a Earth.
So this leads to some other questions:
- Q: Doesn't SqlServer have geospatial methods available? A: Yes for sql server version 2008 and later.
- Q: If Sql has this available using the
Geography
methods, should I use the above math? A: No if you're on Sql Server 2008 or later. If before that, then you have no choice but you have to use that way/formula.
- Q: Are Narwhales, unicorns of the ocean? A: Yes.
Further show off tip - use STDistance .. that's your friend :)
(browser code, not tested, etc)...
-- Arrange.
DECLARE @longitude1 FLOAT = -122.360,
@latitude1 FLOAT = 47.656,
@longitude2 FLOAT = -122.343,
@latitude2 FLOAT = 47.656;
DECLARE @point1 GEOGRAPHY = GEOGRAPHY::STGeomFromText('POINT(' + CAST(@longitude1 AS VARCHAR(10)) + ' ' + CAST(@latitude1 AS VARCHAR(10)) + ')', 4326);
DECLARE @point2 GEOGRAPHY = GEOGRAPHY::STGeomFromText('POINT(' + CAST(@longitude2 AS VARCHAR(10)) + ' ' + CAST(@latitude2 AS VARCHAR(10)) + ')', 4326);
-- Determine the distance (which would be in metres because we're using the 4326 == [common GPS format](http://spatialreference.org/ref/epsg/wgs-84/)).
SELECT @point1.STDistance(@point2);