Information générale
Forum:
Microsoft SQL Server
Versions des environnements
SQL Server:
SQL Server 2008
Please note that the output of the distance calculation from my blog is in MILES, not kilometers. You may need to convert it to kilometers for your own use.
I spent a considerable amount of time optimizing this UDF for performance. One thing I realized is that the PI() function is slow. Since PI isn't about to change anytime soon, it is faster to simply use a constant. SQL Server has a couple of built in functions to convert from radians to degrees and vice versa.
Select Degrees(3.14159), Radians(180.0)
Unfortunately, these functions are slow too. Don't use them.
There was a suggestion early to store your latitude/longitudes in radians instead of degrees. Presumably, this would allow you to simplify the math. Converting from degrees to radians is "simple" math (multiply or divide by a constant). This operation is going to be extremely fast. The distance calculations use several trigonometry functions, which are the slow part. When people talk about lat/long, it is always in degrees (not radians). I wouldn't suggest changing how these values are stored.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement