Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting from distance for geography coordinates
Message
De
22/11/2011 10:29:24
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Getting from distance for geography coordinates
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01529492
Message ID:
01529492
Vues:
77
I have this SQL which returns a list of records where the latitude and longitude and within 250 kilometers of the parameterized latitude and longitude values. Thus, from the point of origin, I am listing all clients within 250 kilometers.
DECLARE @Latitude Float
DECLARE @Latitude2 Float
DECLARE @Longitude Float
DECLARE @Latitude3 Float
DECLARE @Latitude4 Float
DECLARE @Longitude2 Float
DECLARE @Longitude3 Float

SET @Latitude=47.7795
SET @Latitude2=47.7795
SET @Longitude=-65.7191
SET @Latitude3=47.7795
SET @Latitude4=47.7795
SET @Longitude2=-65.7191
SET @Longitude3=-65.7191

SELECT Result.Latitude,Result.Longitude
 FROM (SELECT * FROM Client
 CROSS APPLY (SELECT SIN(@Latitude/57.2957795130823)*SIN(Latitude/57.2957795130823)+
 COS(@Latitude2/57.2957795130823)*COS(Latitude/57.2957795130823)*
 COS(Longitude/57.2957795130823-@Longitude/57.2957795130823) AS Temp) Temp
 WHERE (Latitude>=@Latitude3-250/111.0 AND Latitude<=@Latitude4+250/111.0) AND
  (Longitude>=@Longitude2-250/111.0 AND Longitude<=@Longitude3+250/111.0)) Result
 WHERE 3958.75586574*ACOS(CASE WHEN Temp > 1 THEN 1 WHEN Temp < -1 THEN -1 ELSE Temp END)<=250
In the result, I would like to obtain the distance. What kind of modifications can I apply to obtain the distance value from the point of origin for all records as par of the result set?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform