PI() Examples in SQL Server

In SQL Server, the T-SQL PI() function is a mathematical function that returns the constant value of π (pi).

Syntax

The syntax goes like this:

PI ( )   

So no arguments are required (or accepted).

Example 1 – Basic Usage

Here’s an example to demonstrate.

SELECT PI() Result;

Result:

+------------------+
| Result           |
|------------------|
| 3.14159265358979 |
+------------------+

Example 2 – Reduced Precision

Here’s an example of displaying π using reduced precision. In this case we use the ROUND() function to specify how many decimal places to return.

SELECT ROUND(PI(), 2) Result;

Result:

+----------+
| Result   |
|----------|
| 3.14     |
+----------+

And if we round it to 4 decimal places the digit 5 will be rounded up to 6.

SELECT ROUND(PI(), 4) Result;

Result:

+----------+
| Result   |
|----------|
| 3.1416   |
+----------+

Example 3 – Expressions

Here’s an example of using PI() as part of an expression.

SELECT PI() + 7 Result;

Result:

+------------------+
| Result           |
|------------------|
| 10.1415926535898 |
+------------------+

And another example:

SELECT ROUND(PI(), 2) + 0.3 Result;

Result:

+----------+
| Result   |
|----------|
| 3.44     |
+----------+