numeric functions sql server

Updated : Oct 12, 2019 in SQL server

Numeric functions in SQL Server with examples

in this article, we will discuss numeric functions in SQL server with examples

Numeric functions in SQL
Numeric functions in SQL

few important numeric functions in SQL server with examples we will discuss

ABS() function in SQL examples

abs() function return absolute value of Given Number

select ABS(-253.1678) as AbsNumber 

declare @value float
set @value=-253.1678
select ABS(@value) as AbsNumber


MOD() function in SQL examples

MOD() function we will use to get the remainder from a division

FROM tab;

--Out put:4
SELECT DISTINCT(MOD(UnitPrice,SupplierId)) 
FROM [Product];
SELECT DISTINCT(MOD(UnitPrice,SupplierId)) 
FROM [Product];

POWER() function in SQL Examples

Power() function returns the given number Square Root Value

SELECT POWER(10, 2) as SquareRootValue

--Out Put: 100

ROUND() Function In SQL

ROUND() function returns the given number rounded to the nth decimal place

SELECT ROUND(285.415, 2) AS RoundValue;

--Out Put: 285.420

SELECT ROUND(285.415, 2, 1) AS RoundValue;

--Out Put: 285.410

SIN() Function in SQL

The SIN() function in SQL will return the sine of a number.

SELECT SIN(3) as SinValue

--Out Put: 0.909297426825682

SELECT SIN(-3) as SinValue

--Out Put: -0.909297426825682

SQRT() Function in SQL

The SQRT() function in SQL returns the square root of a number.

select SQRT(16) as SquareRootValue

--Out Put:4

select SQRT(100) as SquareRootValue

--Out Put:10

FLOOR() Function in SQL

The FLOOR() function in SQL returns the largest integer value that is smaller than or equal to a given number.

SELECT FLOOR(30.95) AS FloorValue;

--Out Put:30

SELECT FLOOR(-30.95) AS FloorValue;

--Out Put:-31

EXP() Function In SQL

exp() Function in SQL return e raised to power of given number

SELECT EXP(200) as ExpValue

--Out Put: 7.22597376812575E+86

SELECT EXP(-30.95) AS ExpValue;

--Out Put: 3.6189766840706E-14


Leave a Reply

Your email address will not be published. Required fields are marked *