>>>>My cte only uses the original where - it does not restrict records based on the distance. I do need the final where clause.
>>>
>>>
>>>I give up
>>
>>One of us have some misunderstanding - I suppose it's you in this case.
>
>
>Of course it's me
>
>Count the number of fimes the number 250 occurs in your answer
Can you explain me what does this condition mean
WHERE (Latitude>=@Latitude3-250/111.0 AND Latitude<=@Latitude4+250/111.0) AND
(Longitude>=@Longitude2-250/111.0 AND Longitude<=@Longitude3+250/111.0))
In other words, what exactly this condition is doing?
I think it's building a rectange and then we can filter based on the actual distance. Although what are all the numbers here and constants, it's not clear.
If it's not broken, fix it until it is.
My Blog