SQL Server's substring (expression, start, length) function

Source: Internet
Author: User
Tags expression integer
Syntax for SUBSTRING:    
SUBSTRING (expression, start, length)

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.

Example:

1, starting position is 0, intercept length is 3

Select substring (dwmc,0,3) as SUB,DWMC as DWMC from DW where dwnm= ' 00010010 '

Results:

2, starting position is 1, intercept length is 3

Select substring (dwmc,1,3) as SUB,DWMC as DWMC from DW where dwnm= ' 00010010 '

Results:

3, starting position is-1, intercept length is 3

Select substring (dwmc,-1,3) as SUB,DWMC as DWMC from DW where dwnm= ' 00010010 '

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/

Results:

4, starting position is-2, intercept length is 3

Select substring (dwmc,-2,3) as SUB,DWMC as DWMC from DW where dwnm= ' 00010010 '

Results:

5, starting position is-9, intercept length is 3

Select substring (dwmc,-9,3) as SUB,DWMC as DWMC from DW where dwnm= ' 00010010 '

Results:

Through the example above, we can see that substring interception, similar to the x-coordinate intercept absolute length, and for the string, negative and zero position is empty, the real number of positions from 1 start!

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.