Why are the results different for Excel ATAN2 and T SQL ATN2 ??

  • Hi,

    I'm trying to convert an excel spreadsheet and writing sql functions. One of the formulae on the spreadsheet caculates ATAN2 but when I use the t sql function, ATN2 to replicate the formula, i get a different result.

    X = -12906.5822857173

    Y = -7229.1799706163

    Excel Result = -2.6310162221

    T-SQL Result = -2.08137235178823

    The tolerance limit allowed is 0.03 so obviously the above t-sql result isn't acceptable.

    Can someone tell me why these 2 calculations produce different results? AND how can i fix this?

    Thank You.

  • From

    http://msdn.microsoft.com/en-us/library/ms173854.aspx

    Returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified float expressions.

    I believe that's the reverse interpretation from Excel, which uses point (x, y).

    Try this:

    select ATN2( -12906.5822857173 , -7229.1799706163 )

    select ATN2( -7229.1799706163 , -12906.5822857173 )

    - Adam

  • SERIOUSLY - duh !

    THANK YOU

    P.S: And I won't even tell you that i've been sitting all night and trying to figure out why numbers are not correct :hehe:

    P.S.S: You didn't read the P.S above!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply