Thursday, December 26, 2024

SQL Server ATAN() Function

 The ATAN() function in SQL Server returns the arctangent of a specified number. The arctangent is the inverse of the tangent function and is used to compute the angle (in radians) whose tangent is the specified number.

Syntax:

ATAN(float_expression)

Parameter:

  • float_expression: A numeric expression (of type float) for which you want to calculate the arctangent.

Returns:

  • The function returns a value in radians in the range -π/2 to π/2.

Example Usage:

  1. Basic Example:

    SELECT ATAN(1) AS Arctangent;
    

    Output:

    • The arctangent of 1 is approximately 0.785398 radians (which equals π/4).
  2. Using with a column: Assume you have a table named Angles with a column TangentValues.

    SELECT TangentValues, ATAN(TangentValues) AS Arctangent
    FROM Angles;
    
  3. Convert radians to degrees: To convert the result from radians to degrees:

    SELECT ATAN(1) * (180.0 / PI()) AS ArctangentInDegrees;
    

    Output:

    • The result is approximately 45 degrees.

Notes:

  • If you need to compute the arctangent for two coordinates yy and xx, you can use the ATAN2(y, x) function.
  • The input to the function must be numeric. If a non-numeric value or NULL is passed, the function may return an error or NULL.

No comments:

Post a Comment