# SQL - COT() Function

The SQL COT() function calculates the trigonometric cotangent of a numeric value. This function accepts a single numeric value as an argument. The domain of the argument must be the set of all real numbers except the multiples of π/2. i.e. {x | x ≠ kπ + π/2, k ∈ Z}, where Z represents the set of all the integers and the range of the result will be (-∞, ∞) except when the argument is equal to a multiple of π. If the value passed to this function doesn't lie in the given domain, it raises an error.

The cotangent of an angle is defined as the ratio of the adjacent side of a right triangle to its opposite side. It has a period of π, which means that it repeats itself every π radians (or every 180 degrees). As a result, the domain of the cotangent function is all real numbers except the values where the sine function is zero, since division by zero is undefined.

### Syntax

Following is the syntax of SQL COT() function −

```COT(number)
```

where, number is the value for which we need to calculate the cotangent, in radians.

### Example

If we pass a positive value as an argument, then this function returns it's equivalent cotangent value as shown below −

```SELECT COT(34577098)
AS cotangent_value
```

When we run above program, it produces following result −

```+--------------------+
| cotangent_Value    |
+--------------------+
| 2.33202369272432   |
+--------------------+
```

### Example

In here, we are trying to pass a negative value as an argument to this function, it returns it's equivalent cotangent value which is negative as shown below −

```SELECT COT(-9865.23456789)
AS cotangent_value
```

While executing the above code we get the following output −

```+-------------------+
| cotangent_Value   |
+-------------------+
| -1.36110366584855 |
+-------------------+
```

### Example

We can also pass the mathematical constant PI as an argument to this function, it returns it's equivalent cotangent value.

```SELECT COT(PI())
AS cotangent_value
```

Following is an output of the above code −

```+-----------------------+
| cotangent_Value       |
+-----------------------+
| -8.16561967659769E+15 |
+-----------------------+
```

### Example

If we try to retrieve the cotangent value for 0, we will get an error as shown below −

```SELECT COT(0)
AS cotangent_value
```

Output of the above code is as follows −

```Msg 3623, Level 16, State 1, Line 1
An invalid floating point operation occurred.
```

### Example

Assume we have created a table with name CUSTOMERS as shown below −

```create table CUSTOMERS(ID INT NOT NULL,
NAME VARCHAR(20) NOT NULL,
AGE INT NOT NULL,
SALARY DECIMAL(18, 2),
PRIMARY KEY(ID));
Commands completed successfully.
```

Let us insert r values into it −

```insert INTO CUSTOMERS VALUES(1, 'Ramesh', 32, 'Ahmedabad', 2000.00);
insert INTO CUSTOMERS VALUES(2, 'Khilan', 25, 'Delhi', 1500.00);
insert INTO CUSTOMERS VALUES(3, 'kaushik', 23, 'Kota', 2000.00);
insert INTO CUSTOMERS VALUES(4, 'Chaitali', 25, 'Mumbai', 6500.00);
insert INTO CUSTOMERS VALUES(5, 'Hardik', 27, 'Bhopal', 8500.00);
insert INTO CUSTOMERS VALUES(6, 'Komal', 22, 'MP', 4500.00);
insert INTO CUSTOMERS VALUES(7, 'Muffy', 24, 'Indore', 10000.00);
```

Following query calculates the cotangent value of the salary of all the customers −

```SELECT NAME, AGE, SALARY,
COT(SALARY)
AS cotangent_salaryvalue
FROM CUSTOMERS
```

The result produced is as follows −

```+----------+-----+----------+-----------------------+
| NAME     | AGE | SALARY   | cotangent_salaryvalue |
+----------+-----+----------+-----------------------+
| Ramesh   |  32 |  2000.00 | -0.395101011683924    |
| Khilan   |  25 |  1500.00 |  0.110943943461906    |
| kaushik  |  23 |  2000.00 | -0.395101011683924    |
| Chaitali |  25 |  6500.00 |  22.3066314877133     |
| Hardik   |  27 |  8500.00 | -0.447863405926463    |
| Komal    |  22 |  4500.00 |  0.34417517113566     |
| Muffy    |  24 | 10000.00 |  3.11554495756144     |
+----------+-----+----------+-----------------------+
```
sql-numeric-functions.htm