Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combining a query and a function
Message
 
 
To
13/04/2010 17:28:06
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01460047
Message ID:
01460069
Views:
46
This message has been marked as a message which has helped to the initial question of the thread.
>>What are the values you are testing with?
>
>
>DECLARE @CenterLat Float=47.7795
>DECLARE @CenterLon Float=-65.7191
>DECLARE @SearchDistance Float=250
>
>
>In the table, I have:
>
>47.7795,-65.7191
>47.5993,-65.6506

Try
create table test (Latitude decimal(30,10), Longitude decimal (30,10))

declare @CenterLat float=47.7795
declare @CenterLon float=-65.7191
declare @SearchDistance float=250

 select * from (select * from test T
 cross apply (select SIN(@CenterLat/57.2957795130823) * SIN(Latitude/57.2957795130823) + 
 COS(@CenterLat/57.2957795130823) * COS(Latitude/57.2957795130823) * 
 COS(Longitude/57.2957795130823 -@CenterLon/57.2957795130823) as Temp) Temp
  where (latitude>=@CenterLat - @SearchDistance/111.0 and latitude<=@CenterLat + @SearchDistance/111.0) and
 (longitude>=@CenterLon - @SearchDistance/111.0 and longitude<=@CenterLon + @SearchDistance/111.0)) X
 where  3958.75586574 * ACOS(case when Temp > 1 then 1 when Temp < -1 then -1 else Temp end) <=@SearchDistance
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