Which functions are used by sqlserver?

Source: Internet
Author: User
Tags rtrim

Below are the many functions I use in sqlserver. What other functions do you use? Or which function is useful? Or what functions do you not need?

 

Left (character_expression, integer_expression)
Returns the number of characters starting from the left of the string.
Example:
Select left ('My name is viwo ', 4)
My n

 

Right (character_expression, integer_expression)
Returns the number of integer_expression characters specified from the right.
Example:
Select right ('My name is viwo ', 4)
Viwo

 

Cast (expression as data_type)
Explicitly converts a data type expression to another data type. Cast and convert provide similar functions.
Example:
Select cast (2 as varchar (10) + Cast (11 as varchar (10 ))
211

 

Convert (data_type [(length)], expression [, style])
Explicitly converts a data type expression to another data type. Cast and convert provide similar functions.
Example:
Select convert (varchar, getdate (), 112)
20070328

 

Dateadd (datepart, number, date)
Returns a new datetime value based on a specified date.
Example:
Select dateadd (month, 2, getdate ())
14:24:37. 280

 

Coalesce (expression [,... n])
Returns the first non-empty expression in the parameter.
Example:
Select coalesce (null, null, 0)
0
Select coalesce (2, 3, 0)
2

 

Charindex (expression1, expression2 [, start_location])
Returns the starting position of the specified expression in the string.
Example:
Select charindex ('AB', 'abcd ')
2

 

Ltrim (character_expression)
Returns a character expression after the start space is deleted.
Example:
Select ltrim ('abc ')
ABC

Rtrim (character_expression)
Returns a string after all trailing spaces are truncated.
Example:
Select rtrim ('abc ')
ABC

 

Round (numeric_expression, length [, function])
Returns a numeric expression rounded to the specified length or precision.
Example:
Select round (748.585, 2)
748.590

 

Floor (numeric_expression)
Returns the maximum integer that is less than or equal to the given numeric expression.
Example:
Select floor (748.585)
748

 

Ceiling (numeric_expression)
Returns the smallest integer greater than or equal to the given numeric expression.
Example:
Select ceiling (1, 748.585)
749

 

Replace ('string _ expression1', 'string _ expression2', 'string _ expression3 ')
Replace all the second given string expressions in the first string expression with the third expression.
Example:
Select Replace ('dalian XXXX office Dalian XXXX ', 'dalian', 'beijing ')
Beijing XXXX Office

 

Count
Sum
Min
Max
AVG
Needless to say, five common collection functions

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.