Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting from distance for geography coordinates
Message
From
22/11/2011 10:48:57
 
 
To
22/11/2011 10:29:24
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01529492
Message ID:
01529506
Views:
66
This message has been marked as the solution to the initial question of the thread.
>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(@Latitude/57.2957795130823)*COS(Latitude/57.2957795130823)*
> COS(Longitude/57.2957795130823-@Longitude/57.2957795130823) AS Temp) Temp
> WHERE (Latitude>=@Latitude-250/111.0 AND Latitude<=@Latitude+250/111.0) AND
>  (Longitude>=@Longitude-250/111.0 AND Longitude<=@Longitude+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 field from the point of origin for all records as par of the result set?


The where clause restricts to distances < = 250 km - that clause calculates the distance

So I would add a select item
 3958.75586574*ACOS(CASE WHEN Temp > 1 THEN 1 WHEN Temp < -1 THEN -1 ELSE Temp END)  as Distance
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform