Skip to content

Instantly share code, notes, and snippets.

@josheinstein
Last active July 18, 2019 20:07
Show Gist options
  • Save josheinstein/08c7cc65a1e579aca20349237ea93d01 to your computer and use it in GitHub Desktop.
Save josheinstein/08c7cc65a1e579aca20349237ea93d01 to your computer and use it in GitHub Desktop.
Calculates the distance, in miles, between two LERG VH coordinates.
-- =============================================
-- Author: Josh Einstein
-- Create date: 2/19/2005
-- Description: Calculates the distance between two VH coordinates.
-- =============================================
ALTER FUNCTION [dbo].[DistanceBetween]
(
@v1 int,
@h1 int,
@v2 int,
@h2 int
)
RETURNS int
AS
BEGIN
DECLARE @result int
DECLARE @vDiff int
DECLARE @hDiff int
SET @vDiff = ABS(@v1-@v2)
SET @hDiff = ABS(@h1-@h2)
SET @result = CEILING( SQRT( ( POWER( @vDiff, 2 ) + POWER( @hDiff, 2 ) ) / 10 ) )
RETURN @result
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment