1. 程式人生 > >Sqlserver 計算兩坐標距離函數

Sqlserver 計算兩坐標距離函數

serve sta spa returns tdi res cti lse end

mark

if exists (select * from dbo.sysobjects where id = object_id(NUF_ETL_GetDistance) and xtype in (NFN, NIF, NTF))
    drop function UF_ETL_GetDistance
GO

CREATE FUNCTION UF_ETL_GetDistance
( 
   @sLng    DECIMAL(12,6),
   @sLat    DECIMAL(12,6),
   @eLng    DECIMAL(12,6),
   @eLat    DECIMAL
(12,6) ) RETURNS DECIMAL(12,4) AS BEGIN DECLARE @result DECIMAL(12,4) SELECT @result = 6378137.0*ACOS(SIN(@sLat/180*PI())*SIN(@eLat/180*PI())+COS(@sLat/180*PI())*COS(@eLat/180*PI())*COS((@sLng-@eLng)/180*PI())) RETURN @result/1000 END go

Sqlserver 計算兩坐標距離函數