--The first parameter is the string to be intercepted, the second argument is truncated from the first character, and the third argument is the length of the Intercept.
--For example: Select SUBSTRING (' 12345678 ', 1,4) returns 1234
--Select SUBSTRING (' 12345678 ', 0,4) returns 123
Select SUBSTRING (' 12345678 ', 1,4)
Grammar The CHARINDEX (expression1, Expression2, [start_location]) parameter
expression1 An expression that contains the order of the characters to look for.
expression1 is an expression of a short character data type classification.
expression2 An expression, typically a column that is used to search for a specified sequence.
expression2 belongs to the string data type classification.
Start_location The starting character position when searching for
expression1 in
expression2 . If there is no given
start_location, but a negative number or 0, the search begins at the beginning of the
expression2 .
Select Charindex (' _ ', ' 1767252_ direct success ', 0)--//return 8
Usage of substring and charindex in SQL