April 1, 2026 at 10:51 pm
I have a table with latitude longitude in the format. 45.123456 , -111.123456 , Primary Key . I want to find all ids within a radius in miles.
Thanks in advance . Have a great day.
April 2, 2026 at 12:46 am
You use the (longitude, latitude) to create/define a @Point. and then you use STDistance to calculate the distance between them.
STDistance (geography Data Type) - SQL Server | Microsoft Learn
April 2, 2026 at 5:05 am
Thanks that was a good exercise but that's for two points . I was hoping some type of calculation that draws a radius and returns all the points that fall within that radius or circle. If you have any links for radius please share.
April 2, 2026 at 8:00 am
Thanks that was a good exercise but that's for two points . I was hoping some type of calculation that draws a radius and returns all the points that fall within that radius or circle. If you have any links for radius please share.
All points inside a circle of radius x? That's an infinite number.
April 2, 2026 at 10:06 pm
x
April 2, 2026 at 10:23 pm
If you cannot provide a concise answer . Please move onto the next topic . Have a great day and sql on!
April 4, 2026 at 12:37 am
Sorry, wrong function. you want STContains.
Remarks
STContains() always returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.
Examples
The following example uses STContains() to test two geometry instances to see if the first instance contains the second instance.
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g.STContains(@h);
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply