Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting from distance for geography coordinates
Message
From
22/11/2011 11:50:44
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01529492
Message ID:
01529538
Views:
23
>>>>>Thought I would
>>>>
>>>>While at it, this was the original SQL. If that version would be used, where exactly would be the place to put the required syntax to collect the distance value in the result set:
>>>>
>>>>
>>>>DECLARE @Latitude Float
>>>>DECLARE @Latitude2 Float
>>>>DECLARE @Longitude Float
>>>>DECLARE @Longitude2 Float
>>>>DECLARE @Latitude3 Float
>>>>DECLARE @Latitude4 Float
>>>>DECLARE @Longitude3 Float
>>>>DECLARE @Latitude5 Float
>>>>DECLARE @Latitude6 Float
>>>>DECLARE @Longitude4 Float
>>>>DECLARE @Latitude7 Float
>>>>DECLARE @Latitude8 Float
>>>>DECLARE @Longitude5 Float
>>>>
>>>>SET @Latitude=47.7795
>>>>SET @Latitude2=47.7795
>>>>SET @Longitude=-65.7191
>>>>SET @Longitude2=-65.7191
>>>>SET @Latitude3=47.7795
>>>>SET @Latitude4=47.7795
>>>>SET @Longitude3=-65.7191
>>>>SET @Latitude5=47.7795
>>>>SET @Latitude6=47.7795
>>>>SET @Longitude4=-65.7191
>>>>SET @Latitude7=47.7795
>>>>SET @Latitude8=47.7795
>>>>SET @Longitude5=-65.7191
>>>>
>>>>SELECT Client.Numero FROM 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) AND
>>>> 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)<=250
>>>>
>>>
>>>
>>>;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
>>
>>
>>I see 250 too many times. The 250 is in both where clauses
>
>Right, but it was in the original select statement as well. I want to attempt to filter data first as it was using and then apply distance filter. In case of CTE it may not be relevant, but in case of temp table it will.


No, this was the original SQL Re: Getting from distance for geography coordinates Thread #1529492 Message #1529521

Relevant or not - it's sloppy programming to say the least
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform