SQL Server: Reading notes from the book of "The Must-Know" (eight)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.