@codinglobsters
SOL
FUNCTIONS
Qco
Aters
SWIPE
er
Microsoft SQL Server provides a wide range
of built-in functions that can be used to
manipulate and analyze data in various
ways.
Let's learn some of the commonly used
types of built-in functions.
Date Time functions
SQL Date Time functions are used to
manipulate and format date and time
values.
EXAMPLES
Returns the current system date
GETDATE) and time in the format YYYY-MM
DD HH:MI:SS.
Returns a specific part of a date,
DATEPART)
such as the year, month, or day.
Returns the difference between
DATEDIFF0 two dates in a specified unit, such
as days or hours
Adds or subtracts a specified time
DATEADD) interval (such as days, hours, or
minutes) to a date.
Aggregate functions
SQL Aggregate functions are used to
perform calculations on a set of rows and
return a single value as the result.
EXAMPLES
Returns the number of rows that
cOUNT)
match a specified condition.
Returns the sum of a numneric
SUM) column.
Returns the average value of a
AVG) numeric column.
Returns the smallest value in a
MINO column.
Returns the maximum value in a
MAX) column.
String Functions
SQL String functions help you modify
and work with text data in your database,
like combining words, finding specific
words, trimming,and formatting.
EXAMPLES
Used to concatenate two or more
cONCATO
strings into a single string.
Used to convert a specified string
UPPER)
to all uppercase letters.
Used to convert a specified string
LOWERO to all lowercase letters.
Used to replace all occurrences of
REPLACE) a substring in a specified string
with a new substring.
Mathematical Functions
SQL Mathematical functions are used to
perform calculations and operations on
numerical data within a SQL query.
EXAMPLES
Returns the absolute (positive)
ABS) value of a number, regardless of
its sign.
Returns the smallest integer value
CEILING0 that is greater than or equal to a
given number.
Returns the largest integer value
FLOOR) that is less than or equal to a given
number.
Returns the square root of a given
sQRTO number.
Ranking Functions
SQL Ranking functions are used to assign
a rank or row number to each row within
a result set.
EXAMPLES
Assigns a unique ranking to each
rowwithin a result set, where ties
RANKO are assigned the same rank and
the next consecutive rank is not
skipped.
Assigns a unique ranking to each
row within a result set, where ties
DENSE_RANK) are assigned the same rank and
the next consecutive rank is
skipped.
Returns the number of rows that
ROW_NUMBER)
match a specified condition.