Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combining a query and a function
Message
 
To
13/04/2010 16:46:28
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01460047
Message ID:
01460054
Views:
80
This message has been marked as the solution to the initial question of the thread.
>>After reading your post one more time, I'm not so sure that I'm understanding your question right :o))
>
>As Naomi mentioned, I would like to get rid of this function and have total control into one SQL command.

O!
OK.
Try this:
declare @CenterLat float=47.7795
declare @CenterLon float=-65.7191
declare @SearchDistance float=250

select *
      from test
where (latitude>=@CenterLat - @SearchDistance/111.0 and latitude<=@CenterLat + @SearchDistance/111.0)   AND
      (longitude>=@CenterLon - @SearchDistance/111.0 and longitude<=@CenterLon + @SearchDistance/111.0) AND
      3958.75586574 * ACOS(CASE WHEN SIN(@Latitude1/57.2957795130823) * SIN(@Latitude2/57.2957795130823) + 
                                     COS(@Latitude1/57.2957795130823) * COS(@Latitude2/57.2957795130823) * COS(@Longitude2/57.2957795130823 - @Longitude1/57.2957795130823) < -1
                                     THEN -1
                                WHEN SIN(@Latitude1/57.2957795130823) * SIN(@Latitude2/57.2957795130823) + 
                                     COS(@Latitude1/57.2957795130823) * COS(@Latitude2/57.2957795130823) * COS(@Longitude2/57.2957795130823 - @Longitude1/57.2957795130823) > 1
                                     THEN 1
                           ELSE 
                                     SIN(@Latitude1/57.2957795130823) * SIN(@Latitude2/57.2957795130823) + 
                                     COS(@Latitude1/57.2957795130823) * COS(@Latitude2/57.2957795130823) * COS(@Longitude2/57.2957795130823 - @Longitude1/57.2957795130823) < -1 END) <=@SearchDistance
Just change @Latitude1, @Latitude2, @Longitude1, @Longitude2 to their real names (I'm too lazy right now :o))))
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform