I have a couple of examples saved in my snippets.
here's an example of finding points that are within 5 US Miles; you can change the constants to be in kilometers instead.
declare @radius decimal(18,2)
DECLARE @radians float
SELECT @radians = 57.295779513082323 --> 180/PI
SELECT @radius=5
with cteDistCalc
as(
SELECT t1.*,
DistanceInMiles = 3963.0*acos(sin(t1.Latitude/(@radians)) * sin(t2.Latitude/(57.295779513082323))
+ cos(t1.Latitude/(@radians)) * cos(t2.Latitude/(@radians)) * cos(t2.Longitude/(@radians) - t1.Longitude/(@radians)))
FROM dbo.ZipCodes t1
JOIN dbo.ZipCodes t2
on t1.Latitude between t2.Latitude - @radius and t2.Latitude + @radius
and t1.Longitude between t2.Longitude - @radius and t2.Longitude + @radius
where t1.ZipCode='10023'
)
select * from cteDistCalc WHERE DistanceInMiles < @radius
ORDER BY DistanceInMiles
Lowell