SQL Server Functions (example)

Source: Internet
Author: User
Tags rtrim

--sql SERVER 2008 Functions Daquan
/*
Author:tracylee
Csdncount:travylee
*/

/*
One, the string function:
1. ASCII (string expression)
Returns the ASCII code of the rightmost character in a string
Example: Select ASCII (' abc ')
return:97
2, char (string expression)
Convert ASCII code to the corresponding character
Example: Select char (97)
Return:a
3, CHARINDEX (string expression 1, string expression, 2[, integer expression])
String 2 finds the string 1 if it exists, returns the first existing position if it does not exist, and returns 0
If there is a null in string 1 and string 2, NULL is returned. An integer expression can indicate that the word
The starting position of the search in the character string 2
Example: Select CHARINDEX (' A ', ' basketball ')--return:2
Select CHARINDEX (' A ', ' Basketball ', 3)--return:8
4, Difference (string expression 1, string expression 2)
Determines the similarity of two strings, returns an integer in 0-4, 0 means hardly similar or is completely
Similar, 4 means almost similar or completely similar
Example: Select difference (' Tracy ', ' Tracy ')--return:4
Select difference (' Kobe ', ' Tracy ')--return:0
5, Left (string expression, integer expression)
Returns the character of a string expression 1, starting from the left, specifying the number of integers
Example: Select Left (' Tracy ', 2)--return:tr
6, right (string expression, integer expression)
Returns a character that specifies the number of integers in string expression 1, starting from the right
Example: Select Right (' Tracy ', 2)--return:cy
7, datalength (string expression)
Returns the number of bytes in a string expression
Example: Select Datalength (' Tracy ')--return:5
Select Datalength (' China ')--return:4
8, Len (string expression)
Returns the number of characters in a string expression
Example: Select Len (' Tracy ')--The return value is: 5
Select Len (' China ')--The return value is: 2
9, LTrim (string expression)
Remove the space to the left of the string expression
Example: Select LTrim (' Tracy ')--return:tracy
10, RTrim (string expression)
Remove the space to the right of the string expression
Example: Select RTrim (' Tracy ')--return:tracy
11, substring (string, integer-expression 1, integer-expression 2)
A string that intercepts an integer expression 2 length from an integer expression in a string of 2 bits
Example: Select substring (' Tracyleebaihe ', 3,2)--return:ac
12, lower (string expression) and upper (string expression)
The former converts the uppercase letters in the string to lowercase, the latter vice versa. If the string does not contain
Letter, blame return to original string
Example: Select lower (' Pinball tttt Pinball ')--return: Bomb TTTT Pinball Hall
Example: Select Upper (' Pinball tttt Pinball ')--return: Bomb TTTT Pinball Hall
Example: Select lower (' string ')--return: string
Example: Select upper (' String ')--return: string
13, reverse (' string expression ')
Invert string expression to return a new string after inversion
Example: Select reverse (' Read dead book ')--return: Book dead Read
14, Stuff (string expression 1, start position, length, string expression 2)
In string expression 1, removes the specified length of characters from the specified starting position, and inserts the
into the specified string expression 2
Example: Select Stuff (' Tracyxxxbaihe ', 6,3, ' Lee ')--return:tracyleebaihe
15, replace (string expression 1, string expression 2, string expression 3)
Replaces the string expression 2 that appears in string expression 1 with the string expression 3, returning the
New string after the change
Example: Select replace (' Tracyxxxbaihe ', ' xxx ', ' Lee ')--return:tracyleebaihe
*/

SQL Server Functions (example)

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.