I've written this SQL Script:
DECLARE @location geography
DECLARE @radius int
SET @location = (SELECT Location FROM Hydrants WHERE HydrantId = 2)
SET @radius = (SELECT Radius FROM Hydrants WHERE HydrantId = 2)
SELECT *
FROM Sites
WHERE @location.STDistance(location) < @radius
ORDER BY SiteId ASC
I did this to refactor it
SELECT *
FROM Sites, Hydrants
Inner Join Hydrants.Location.STDistance(Sites.Location) < Hydrants.Radius
WHERE Hydrants.HydrantId = 2
ORDER BY Sites.SiteId ASC;
but without luck.
Any advice will be welcome.
geographydata type, starting with 2K8.