Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting from distance for geography coordinates
Message
 
 
To
22/11/2011 11:40:52
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01529492
Message ID:
01529531
Views:
21
>>
>>;with cte as (SELECT Client.Numero, 3958.75586574*ACOS(
>> CASE WHEN SIN(@Latitude3/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>           COS(@Latitude4/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>           COS(Client.Longitude/57.2957795130823-@Longitude3/57.2957795130823)<-1
>>           THEN -1
>>      WHEN SIN(@Latitude5/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>           COS(@Latitude6/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>           COS(Client.Longitude/57.2957795130823-@Longitude4/57.2957795130823)>1
>>           THEN 1
>>      ELSE SIN(@Latitude7/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>           COS(@Latitude8/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>           COS(Client.Longitude/57.2957795130823-@Longitude5/57.2957795130823)
>> END) as Distance
>>
>>FROM dbo.Client
>>
>>
>> WHERE (Client.Latitude>=@Latitude-250/111.0 AND Client.Latitude<=@Latitude2+250/111.0) AND
>>(Client.Longitude>=@Longitude-250/111.0 AND Client.Longitude<=@Longitude2+250/111.0) )
>>
>>select * from cte where Distance <=250
>
>Thanks, I am always trying to avoid that syntax as it makes it more difficult to migrate to another backend.

Instead of using CTE use derived table.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform