
If there is a student table, where the student's name is their Chinese (English) name, how to obtain the English name in parentheses
Two SQL functions need to be combined, one is the PATINDEX() function or the charindex() function, and the other is the substring() function
PATINDEX() function
1. Concept:
Patindex is a function used to return the starting position of a specified pattern, where the pattern is a literal string that can contain wildcard characters. The starting position starts from 1, and when it is known that the string in the pattern exists in the expression, it will return the first occurrence position. If it does not exist, return the number 0.
2. Format:
Grammar format: PATINDEX ('% pattern%', expression).
Explanation: Pattern: is a string used for detection. Expression is an expression that can be any valid data type. Pattern will be used in the expression for detection. If it exists, it returns the first occurrence position. If it does not exist, it returns 0. The index position starts from 1.
3. Specific format:
PATINDEX ('% pattern%', expression): Fuzzy query before and after specified string
The charindex() function
The charindex() function and the PATINDEX() function have the same function, both returning the starting position of a character or string in another string. The difference between them is that PATINDEX can use wildcards, while CHARINDEX cannot
SUBSTRING function
1. Concept
The SUBSTRING() function is used to extract characters from text fields.
2. Format SUBSTRING (columnname, start, length).
Description: Column_Name is the column to extract characters from
My_Column_Name is the name to be displayed for custom results
Start is the starting position for truncation (1 is the first character, truncating 0 characters)
Length is the remaining character length to be returned after truncating a character
These two functions work together to obtain the content we need
