I imagine you could code it to look for that specific case and handle it differently like this.

Greg

```
FUNCTION [dbo].[f_Distance] (
@latitude1 DECIMAL(19,16),
@longitude1 DECIMAL(19,16),
@latitude2 DECIMAL(19,16),
@longitude2 DECIMAL(19,16)
)
RETURNS DECIMAL(19,12)
AS
BEGIN
DECLARE @a DECIMAL(19,16)
DECLARE @Distance DECIMAL(19,12)
IF @latitude1 = @latitude2 AND @longitude1 = @longitude2
BEGIN
-- Convert to degrees to radians
SET @latitude1 = @latitude1 / 180.0000000000 * PI()
SET @longitude1 = @longitude1 / 180.0000000000 * PI()
SET @latitude2 = @latitude2 / 180.0000000000 * PI()
SET @longitude2 = @longitude2 / 180.0000000000 * PI()
SET @a = (@longitude1 - @longitude2)
IF ( @a > PI() ) SET @a = 2 * PI()
SET @Distance = ACOS(
SIN(@latitude2) * SIN(@latitude1) + COS(@Latitude2) * COS(@Latitude1) * COS(@a)
) * 6371.00000000000000
END
ELSE
BEGIN
SET @Distance = 0
END
RETURN @Distance
END
```