I found the solution for this question in C#, but I can't translate it to a single query T-SQL, since my C# implementation requires branching (if then else).
I also found the following C# solution, which could be translated to a single query T-SQL but it doesn't produce the correct results
public static double GetAzimuth(WGSCoord c1, WGSCoord c2) {
var lat1 = DegToRad(c1.Latitude);
var lon1 = DegToRad(c1.Longitude);
var lat2 = DegToRad(c2.Latitude);
var lon2 = DegToRad(c2.Longitude);
return RadToDeg(Math.Asin(Math.Sin(lon1 – lon2) * Math.Cos(lat2) / Math.Sin(Math.Acos(Math.Sin(lat2) * Math.Sin(lat1) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(lon2 – lon1)))));
}
Code from Tamir Khason – Just code
Could someone correct the code above or provide an alternate solution?