Lesson 8th using functions to process data
8.1 Functions
"Noun" portable: The code you write can run on multiple systems
8.2 Using Functions
8.2.1 Text Processing functions
Example 1: Using the UPPER () function--Convert text to uppercase
SELECT UPPER as Vend_name_upcase from Vendors ORDER by Vend_name;
Commonly used text-processing functions:
- Left (): Returns the character to the ieft of the string
- DATALENGTH (): Returns the length of a string
- LOWER (): Converts a string to lowercase
- LTRIM (): Remove the space to the left of the string
- RTRIM (): Remove the space to the right of the string
- UPPER (): Converts a string to uppercase
8.2.2 Date and time processing functions
Example 2: Retrieving all orders for 2012 in the Orders table
SELECT Order_num from Orders WHERE DATEPART = ' - ' ; -- Analysis: DATEPART () returns the year only from the Order_date column. By comparing with 2012, the WHERE clause filters only orders for this year
8.2.3 Numeric processing function
Numeric processing functions work with numeric data only. These functions are generally used primarily for algebraic, triangular, or geometric operations.
8.3 Summary
Describe the use of functions
Sequel:
SQL Server: Reading notes from the book of "The Must-Know" (vii)
SQL Server: Reading notes from the book of "The Must-Know" (eight)