# Mathematical Functions in SQL – SQL Server Tutorial

## MATHEMATICAL FUNCTIONS :-

### Abs( ) Mathematical Function in SQL:-

It returns absolute value.

Example :-

Select abs (-10)
↓
Output →10

### Sign ( ) Mathematical Function in SQL:-

Syntax :- Sign(expr)

If expr is

• + (plus)         →              1
• – (minus)      →            -1
•    0                      →             0

Example :-

•           Select sign (-10)                   select     sign   (10-10)
•                   ↓                                                   ↓
•           Output →   -1                              Output →    0

### Power  ( ) Mathematical Function in SQL:-

• Used to calculate power
• power(m,n)

Example  :-

• Select power (3,2)       (mn)
•             ↓
• Output     →  9

### Sqrt ( ) Mathematical Function in SQL:-

• Returns squre root.
• Select sqrt(16)

↓

Output  → 4

### Square ( ) Mathematical Function in SQL:-

• It returns square of a number.
• Select square (5)

↓

Output  → 25

### Round ( ) Mathematical Function in SQL:-

• Rounds a number to specify no of decimal places.

Syntax : round (number,decimal places[1/10])

Example :-

Select round (3.456,2)

↓                           {default+0 →rounded,  default+1 → truncated}

Output   → 3.46

Select round(3.553,0)

↓

Output    → 4

Select round (385.456,-2)     {means integer part +means decimal part}

↓

Output    → 400

Select round (325,456,-1)

↓

Output     →330

Select round (325,456,-0)

↓

Output   → 0

Select round (3.456,2,1)

↓

Output  →3.45

### Ceiling ( ) Mathematical Function in SQL:-

• It returns highest value.
• Select ceiling (3.123)

↓

Output   → 4

### Floor ( ) Mathematical Function in SQL:-

• Returns least integer.
• Select floor(3,921)

Output  →3