Example
Return the absolute value of a number:
SELECT Abs(-243.5) AS AbsNum;
Definition and Usage
The ABS() function returns the absolute value of a number.
Syntax
ABS(number)
Return the absolute value of a number:
SELECT Abs(-243.5) AS AbsNum;
The ABS() function returns the absolute value of a number.
ABS(number)
Convert the text to upper-case:
SELECT UPPER('SQL Tutorial is FUN!');
The UPPER() function converts a string to upper-case.
Note: Also look at the LOWER() function.
UPPER(text)
Return an integer value (the Unicode value), for the first character of the input expression:
SELECT UNICODE('Atlanta');
The UNICODE() function returns an integer value (the Unicode value), for the first character of the input expression.
UNICODE(character_expression)
Remove leading and trailing spaces from a string:
SELECT TRIM(' SQL Tutorial! ') AS TrimmedString;
The TRIM() function removes the space character OR other specified characters from the start or end of a string.
By default, the TRIM() function removes leading and trailing spaces from a string.
Note: Also look at the LTRIM() and RTRIM() functions.
TRIM([characters FROM ]string)
Return the string from the first argument AFTER the characters specified in the second argument are translated into the characters specified in the third argument:
SELECT TRANSLATE('Monday', 'Monday', 'Sunday'); // Results in Sunday
The TRANSLATE() function returns the string from the first argument after the characters specified in the second argument are translated into the characters specified in the third argument.
Note: The TRANSLATE() function will return an error if characters and translations have different lengths.
TRANSLATE(string, characters, translations)
Extract 3 characters from a string, starting in position 1:
SELECT SUBSTRING('SQL Tutorial', 1, 3) AS ExtractString;
The SUBSTRING() function extracts some characters from a string.
SUBSTRING(string, start, length)
Delete 3 characters from a string, starting in position 1, and then insert “HTML” in position 1:
SELECT STUFF('SQL Tutorial', 1, 3, 'HTML');
The STUFF() function deletes a part of a string and then inserts another part into the string, starting at a specified position.
Tip: Also look at the REPLACE() function.
STUFF(string, start, length, new_string)
Return a number as a string:
SELECT STR(185);
The STR() function returns a number as a string.
STR(number, length, decimals)
Return a string with 10 spaces:
SELECT SPACE(10);
The SPACE() function returns a string of the specified number of space characters.
SPACE(number)
Evaluate the similarity of two strings, and return a four-character code:
SELECT SOUNDEX('Juice'), SOUNDEX('Jucy');
The SOUNDEX() function returns a four-character code to evaluate the similarity of two expressions.
Note: The SOUNDEX() converts the string to a four-character code based on how the string sounds when spoken.
Tip: Also look at the DIFFERENCE() function.
SOUNDEX(expression)