SQL Server PI() Function
The SQL Server (Transact-SQL) PI() function returns the value of 𝜋 (pi).
Syntax
PI()
Parameters
No parameter is required.
Return Value
Returns the value of 𝜋.
Example 1:
The example below shows the usage of PI() function.
SELECT PI(); Result: 3.141592653589793
Example 2:
Consider a database table called Sample with the following records:
Data | Radius |
---|---|
Data 1 | 1 |
Data 2 | 2 |
Data 3 | 3 |
Data 4 | 4 |
Data 5 | 5 |
The statement given below can be used to calculate the area of the circle where radius is specified by values of column Radius.
SELECT *, (PI() * Radius * Radius) AS Area FROM Sample;
This will produce the result as shown below:
Data | Radius | Area |
---|---|---|
Data 1 | 1 | 3.141592653589793 |
Data 2 | 2 | 12.566370614359172 |
Data 3 | 3 | 28.274333882308138 |
Data 4 | 4 | 50.26548245743669 |
Data 5 | 5 | 78.53981633974483 |
❮ SQL Server Functions