SQL Functions

String  Functions

a) Upper Function: Upper function is used to convert all the characters in upper case.


select upper(field) from table;

b) Lower Function:  Lower function is used to convert all character in lower case of field/string.


 select lower(field) from table;

c) Concat Function: Concat function is used to concatenate for than one filed/string.


select concat(field1,field2) from table

d) Length Function: Length function is used to get the length of field/string value.


select length(field) from table

e) Trim Function: Trim Function is used for remove trailing or leading space from field/string .


select trip(field) from table;

f) Substring Function: Substring function is used for extract a substring from field/string


 select substring(field, start position, length) from table

g) Replace Function: Replace function is used to replace a substring in string with other substring.


 select replace(field, old_substring, new_substring)

Date Function

a) GETDATE function: GetDate function is used to get the current date and time.


select GETDATE() from table;

b) DATEPART Function: To extract the specific part of date DATEPART Function is used .


 select dateprt(part, date) from table;

c) DATEADD Function: DATEADD function is used to add a specific number of unit a date value.


select dateadd(unit, value, date) from table

d) DATEDIFF Function: To calculate the difference of two date datediff function is used.


select datediff(unit, start_date, end_date) from table

e) Year Function : Year function is used to extract the year from date.


select year(date field) from table;

Aggregate Function

a) Count Function: Count Function is used to get the number of rows in a table.


select count(field) from table

b) SUM Function: SUM Function is used to get the sum of numeric field value.


select sum(field) from table

c) AVG Function: AVG Function is used to get the average of numeric field value.


select avg(field) from table;

d) MIN Function: MIN Function is used to get the minimum value.


select min(field) from table;

e) MAX Function: MAX Function is used to get the maximum value.


select max(field) from table;

Keep Learning 🙂

Leave a Reply

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