SQL Server substring function usage Summary _mssql

Source: Internet
Author: User
Tags sql server substring
The SUBSTRING function was used when manipulating SQL Server
SUBSTRING (expression, start, length)

Parameters
Expression
A string, binary string, text, image, column, or an expression that contains a column. Do not use an expression that contains aggregate functions.

Start
An integer or an expression that can be implicitly converted to int, specifying the start position of the substring.

Length
An integer or an expression that can be implicitly converted to int, specifying the length of the substring (but the result and a complement of length character lengths depends on the length of the expression and the setting of the start!!!!!!!!!!! )。

return value
If expression is a supported character data type, the character data is returned. If expression is a supported binary data type, the binary data is returned. If start = 1, the substring starts with the first character of the expression

To add, the start position setting, if set to 1, will start counting from the first character, 2,3,4 ...

Select substring (ziduan,1,6)

The first 6 characters of the field, such as 200908, will be selected.

If set to 0,

The same execution select substring (ziduan,0,6)

The result will be 20090, if you change to 1.

Also executes select substring (ziduan,-1,6)

The result will be 2009.

Same -2,-3,................. By analogy
Here are some other articles on the network.
SUBSTRING (' 98765 ', -1,3) results: 9
SUBSTRING (' 98765 ', 0, 3) Results: 98
SUBSTRING (' 98765 ', 1, 3) Results: 987
About the function of this situation, I found some information, but still not very clear
SubString ($sourceString, $startingLoc, $length)
$sourceString
The resource string.

$startingLoc
The starting point of the substring in the resource string. If this value is negative or 0, only those characters whose location is greater than 0 are returned. If this value is greater than the length of the $sourceString, a string of zero length is returned.

$length
[optional] The number of characters to retrieve. If this value is not specified, it returns all characters starting at the position specified in the $STARTINGLOC until the end of the string.

If this value is negative or 0, only those characters whose location is greater than 0 are returned.

Getting Started learning SQL
Select substring (CONVERT (varchar,birthdate), 5,1) as Mon, * FROM Employees
where substring (CONVERT (varchar,birthdate), 5, 1) = ' 8 '
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.