The below code will calculate the distance (Displacement) between two locations based on longitude and latitude. -- ============================================= -- Author: V.U.M.Sastry Sagi -- Create date: 11/30/2010 -- Description: Gets the distance between two locations -- ============================================= CREATE FUNCTION [dbo].[getDistanceBetweenLatLon] ( @lat1 DECIMAL(5, 2), @long1 DECIMAL(5, 2), @lat2 DECIMAL(5, 2), @long2 DECIMAL(5, 2) ) RETURNS NUMERIC(10,