SQL study notes seven function numbers, date, type conversion, null value processing, case

Source: Internet
Author: User
Tags switch case

Numeric Functions
ABS (): returns the absolute value.
CEILING (): round to the maximum integer.
FLOOR (): round to the smallest integer.
ROUND (): ROUND (A, B) A is the number to be processed, and B is the number of digits accurate to the decimal point.
LEN (): calculates the string length.
LOWER () and UPPER (): lowercase and UPPER case
LTRIM (): removes spaces on the left of the string.
RTRIM (): remove the spaces on the right of the string
SUBSTRING (string, start_position, length) string is the string to be processed, start_position is the number of start interceptions, and length is the maximum length of the truncation.

Date Functions
GETDATE (): Get the current date and time
DATEADD (datepart, number, date), calculate the date after the increase
For example, DATEADD (DAY, 3, date) calculates the date of 3 days after date.
DATEADD (MONTH,-8, date) calculates the date of the first 8 months of date
DATEDIFF (datepart, startdate, enddate): calculate the difference between two dates.
DATEPART (datepart, date): returns a specific part of a date.

Type conversion functions
CAST (expression AS data_type)
CONVERT (data_type, expression)

The null value processing function is the second parameter if the query result is null. If it is not null, it is the first parameter.
Select isnull (FName, 'Alias name') as name from T_Employee


CASE function usage
Single-value judgment, equivalent to switch case
CASE expression
WHEN value1 THEN returnvalue1
WHEN value2 THEN returnvalue2
WHEN value3 THEN returnvalue3
ELSE defaultreturnvalue
END

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.