SQL Server calculate distances between 2 sets of columns of latitude / longitude

Viewed 8599

I'm trying to calculate the closest weather station to a given zip code. I have data with the lat/lon for the weather station and the zip codes. I also have a way to calculate distance for a 2 points (here). What I'm looking for is a way to create a column that has the distances for multiple instances.

StationNum  lat     lon     Zip     lat      lon   distance
123         34.66   98.32   12345   33.78   91.91   ???
456         33.03   96.8    23456   35.23   92.23   ???
789         32.29   96.85   34567   33.09   92.68   ???

Is there a way to do that or do I need to write out the math by hand?

1 Answers
Related