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!