GEOGRAPHY Using for MSSQL 2008

MSSQL 2008
用來挑出距離最近的五個點

ALTER PROCEDURE [dbo].[GetNearbyLocations]
   @Latitude float,
   @Longitude float
AS
BEGIN
   SET NOCOUNT ON;
   DECLARE @StartPoint geography;
   DECLARE @g geography;
   
   SET @StartPoint = GEOGRAPHY::STGeomFromText(‘Point(‘ + CAST(@Longitude AS VARCHAR(32)) + ‘ ‘ + CAST(@Latitude AS VARCHAR(32)) + ‘)’,4326)
       
   SELECT top 5 GEOGRAPHY::STGeomFromText(‘Point(‘ + CAST(L.lng AS VARCHAR(32)) + ‘ ‘ + CAST(L.lat AS VARCHAR(32)) + ‘)’,4326).STDistance(@StartPoint) AS distance,* FROM hospital L WHERE enabled=1 ORDER BY distance ASC
END