SQL Server PI() Function

The PI() function is used to return the value of Pi, which is approximately equal to 3.14159265358979.

Syntax

PI()

Use Cases

The PI() function can be used in the following scenarios:

  • When calculating the area, circumference, or arc length of a circle
  • When calculating radian values in trigonometric functions

Examples

Example 1

Calculate the area and circumference of a circle with a radius of 5.

Query:

DECLARE @radius AS FLOAT
SET @radius = 5

SELECT
    ROUND(PI() * POWER(@radius, 2), 2) AS Area,
    ROUND(2 * PI() * @radius, 2) AS Perimeter

Result:

Area Perimeter
78.54 31.42

Example 2

Calculate the sine, cosine, and tangent values of an angle of 45°.

Query:

DECLARE @degree AS FLOAT
SET @degree = 45

SELECT
    SIN(@degree * PI() / 180.0) AS Sine,
    COS(@degree * PI() / 180.0) AS Cosine,
    TAN(@degree * PI() / 180.0) AS Tangent

Result:

Sine Cosine Tangent
0.70710678 0.70710678 0.99999999

Conclusion

The PI() function returns the value of Pi, which can be used in calculations related to circles, as well as in trigonometric functions when converting degrees to radians.