COS() Examples in SQL Server

In SQL Server, the T-SQL COS() function is a mathematical function that returns the trigonometric cosine of the specified angle – measured in radians – in the specified expression.

You specify the angle by providing an argument to the function when calling it.

Syntax

The syntax goes like this:

COS ( float_expression )  

Where float_expression is an expression of type float.

Example 1 – Basic Usage

Here’s an example to demonstrate.

SELECT COS(1) Result;

Result:

+------------------+
| Result           |
|------------------|
| 0.54030230586814 |
+------------------+

And with a different value:

SELECT COS(2) Result;

Result:

+--------------------+
| Result             |
|--------------------|
| -0.416146836547142 |
+--------------------+

Example 2 – Fractions

The argument can have a fractional component.

SELECT COS(1.52) Result;

Result:

+--------------------+
| Result             |
|--------------------|
| 0.0507744849335792 |
+--------------------+

Example 3 – Expressions

You can also use expressions like this:

SELECT COS(1 + 2) Result;

Result:

+--------------------+
| Result             |
|--------------------|
| -0.989992496600445 |
+--------------------+

So using that example, the result is the same as doing this:

SELECT COS(3) Result;

Result:

+--------------------+
| Result             |
|--------------------|
| -0.989992496600445 |
+--------------------+

Example 4 – PI

And here’s an example that uses the T-SQL PI() function as the argument.

SELECT COS(PI()) Result;

Result:

+----------+
| Result   |
|----------|
| -1       |
+----------+