Substring function is used for SQL Server operations.
Substring (expression, start, length)
Parameters
Expression
String, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.
Start
An integer or expression that can be implicitly converted to an int indicates the start position of the substring.
Length
An integer or expression that can be implicitly converted to an int, which refers to the length of the stator string (but the result is supplemented with a length returned, it depends on the Expression length and Start Settings !!!!!!!!!!!).
Return Value
If expression is a supported character data type, character data is returned. If expression is a supported binary data type, binary data is returned. If start = 1, the substring starts with the first character of the expression.
It should be added that, if the start position is set to 1, it will count from the first character, and so on,
Select substring (ziduan, 1, 6)
The first six characters of the field will be selected, for example, 200908.
If it is set to 0,
Similarly, run select substring (ziduan)
The result is 20090. If it is changed to-1
Similarly, run select substring (ziduan)
The result is 2009.
Similarly-2,-3, ...... and so on
Below are some otherArticle.
Substring ('20140901',-98765) Result: 9
Substring ('20140901', 98765) Result: 98
Substring ('20140901', 98765) Result: 987
I found some information about the function, but I still don't quite understand it.
Substring ($ sourcestring, $ startingloc, $ length)
$ Sourcestring
Resource string.
$ Startingloc
The starting point of the substring in the resource string. If the value is negative or 0, only the characters whose position is greater than zero are returned. If the value is longer than $ sourcestring, a zero-length string is returned.
$ Length
[Optional] number of characters to be retrieved. If this value is not specified, it returns all characters starting from the position specified in $ startingloc until the end of the string.
If the value is negative or 0, only the characters whose position is greater than zero are returned.
Getting started with SQL
Select substring (convert (varchar, birthdate), 5, 1) as Mon, * from employees
Where substring (convert (varchar, birthdate), 5, 1) = '8'