Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
P.S. Noting that lat & long are not the same dimensions, pick boundary boxes that are bigger than needed to get a correct/safe pre-filter in all conditions. Still, if there are many points being selected from, this can be a huge speed improvement. Last, if the built-in geo methods support returning points within a bounding box natively, use that instead of my suggested manual bounding box, and definitely instead of calculating the distance to all possible points and then filtering on the calculated distance—because you don't actually care what numeric distance is for unwanted points.
P.S. You may get even more performance improvement by doing a simple arithmetic box before doing the straight-line distance calculation. That is, filter first for those where the value |LatLong.Lat - @geo.Lat| + |LatLong.Long - @geo.Long| < n before you do the more complicated sqrt((LatLong.Lat - @geo.Lat)^2 + (LatLong.Long - @geo.Long)^2). And even better, calculate the upper and lower bounds first, then LatLong.Lat > @geoLatLowerBound && LatLong.Lat < @geoLatUpperBound && LatLong.Long > @geoLongLowerBound && LatLong.Long < @geoLongUpperBound. (This is pseudocode, adapt appropriately.)
@JamesJenkins And what is that alternative? The alternative is the hypothesis that a database could show in state restoring but not actually be restoring. Or it could be at the final step of restoring, with the restore actually completed so that it could actually be set to ONLINE state. So long story short, I think your comment and downvote are out of line for this site and your information is factually incorrect because it is not properly qualified with the data I have presented.
Perhaps you are unfamiliar with how on StackOverflow, we sometimes answer questions that are slightly different from the posted one. This provides value because people often come to questions similar to theirs after searching online. Regarding your factual claim about ALTER DATABASE not being permitted, I assure you that in my case, the database was in fact showing as in restoring state, and using SET ONLINE in fact worked. So realize that you are calling me mistaken or lying. Is that what you really need to do when an alternative is available?