Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combining a query and a function
Message
De
13/04/2010 17:35:05
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01460047
Message ID:
01460071
Vues:
28
>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
This is good code. I also tested it against the main table with close to 2000 records and the related records were returned as is.

Thanks
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform