0% found this document useful (0 votes)
33 views

Functions Definition Syntax

The document defines SQL functions with their syntax. It provides examples of functions like SUM, SQRT, ROUND, RAND, MIN, MAX, CONVERT, CHAR, CHARINDEX, LOWER, REPLACE, DATEPART and ISNULL along with their syntax and usage to return values like sums, square roots, rounded numbers, random numbers, minimums, maximums, converted data types, characters, substrings positions, lowercase, replaced strings, date parts and alternative values for nulls.

Uploaded by

Tj Budong
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Functions Definition Syntax

The document defines SQL functions with their syntax. It provides examples of functions like SUM, SQRT, ROUND, RAND, MIN, MAX, CONVERT, CHAR, CHARINDEX, LOWER, REPLACE, DATEPART and ISNULL along with their syntax and usage to return values like sums, square roots, rounded numbers, random numbers, minimums, maximums, converted data types, characters, substrings positions, lowercase, replaced strings, date parts and alternative values for nulls.

Uploaded by

Tj Budong
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FUNCTIONS DEFINITION SYNTAX

SUM Return the sum of the "Quantity" field SELECT SUM(Quantity) AS


in the "OrderDetails" table: TotalItemsOrdered FROM
OrderDetails;

 SUM(expression)

SQUARE Return the square root of a number: SELECT SQUARE(64);

 SQUARE(number)

SQRT The SQRT() function returns the square SELECT SQRT(64);


root of a number.
 SQRT(number)

SIGN Return the sign of a number. SELECT SIGN(255.5);

 SIGN(number)

ROUND Returns a number rounded to a certain SELECT ROUND(235.415, 2) AS


number of decimal places. RoundValue;

 ROUND(number,
decimal_places, operation)

RAND Return a random decimal number (no SELECT RAND();


seed value - so it returns a completely
random number >= 0 and <1)  RAND(seed)

RADIANS Convert a degree value into radians. SELECT RADIANS(180);

 RADIANS(number)

POWER Return 4 raised to the second power. SELECT POWER(4, 2);

 POWER(m, n)

MIN Find the price of the cheapest product SELECT MIN(Price) AS SmallestPrice
in the "Products" table. FROM Products;

 MIN(expression)
MAX Find the price of the most expensive SELECT MAX(Price) AS LargestPrice
product in the "Products" table. FROM Products;

 MAX(expression)

CONVERT Convert an expression from one data SELECT CONVERT(int, 25.65);


type to another (integer).
 CONVERT(data_type(length),
expression, style)

CHAR Return the character based on the SELECT CHAR(65) AS


number code 65. NumberCodeToCharacter;

 CHAR(number_code)

CHARINDEX Search for "t" in string "Customer", and SELECT CHARINDEX('t', 'Customer')
return position. AS MatchPosition;

 CHARINDEX(substring, string,
start_pos)

LOWER Convert the text to lower-case. SELECT LOWER('SQL Tutorial is


FUN!');

 LOWER(string)

REPLACE Replace a sequence of characters in a SELECT REPLACE('SQL Tutorial', 'T',


string with another set of characters. 'M');

 REPLACE(string1,
string_to_replace,
replacement_string)

SPACE Return a string with 10 spaces. SELECT SPACE(10);

 SPACE(number)

STUFF Delete 3 characters from a string and SELECT STUFF('SQL Tutorial', 1, 3,


then insert another sequence of 'HTML');
characters, starting in position 1:
 STUFF(string1, start, length,
add_string)
UPPER Convert the text to upper-case. SELECT UPPER('SQL Tutorial is
FUN!');

 UPPER(string)

DATEPART Return a specified part of a given date, SELECT DATEPART(year,


as an integer value. '2017/08/25') AS DatePartInt;

 DATEPART(interval, date)

ISNULL Return an alternative value IF the SELECT ISNULL(NULL,


expression is NULL. 'W3Schools.com');

 ISNULL(expression, alt_value)

Members:

Gili, Breart Hrans M.

Garcia, John Lee

Flores, Jaco

Fernandez, Clarence Jaie

You might also like