Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Radius finding from coordinates

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2008-10-27 : 09:26:12
I have a location with longitude and lattitude.
I want to search for ares within a 10 mile radius of this but dont know how to do this is SQL

Have browsed many websites but they all suggest to use POW and ATAN2 which aren't recognised in SQL.

This is what I have tried so far
(
@venue_id int
)
AS

declare @postcode varchar(10)

declare @lat float

declare @long float

declare @radius float
declare @distance float


set @radius = 20
SELECT @postcode = venue_postcode FROM tb_venue WHERE venue_id = @venue_id

SELECT *
FROM tb_properties, tb_venue
WHERE
Prop_Visible = 1
AND
tb_properties.glat >0
AND
tb_properties.glong >0
and
@radius >
((tb_venue.venue_glat - tb_properties.glat)*(tb_venue.venue_glat - tb_properties.glat)) + ((tb_venue.venue_glat - tb_properties.glat)*(tb_venue.venue_glat - tb_properties.glat))
GO

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-27 : 11:07:30
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81360&SearchTerms=latitu
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-27 : 11:16:01
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=112369



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-27 : 11:16:43
quote:
Originally posted by godspeedba

Have browsed many websites but they all suggest to use POW and ATAN2 which aren't recognised in SQL.

POW is spelled POWER in T-SQL and ATAN2 is spelled ATN2 in T-SQL.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -