CHARINDEX is a SQL Server function that returns the starting position of a specified expression within another string. It is useful for locating characters or words inside text.
Finding the position of a character or delimiter is often required when parsing structured text values.
An email address contains an '@' symbol. CHARINDEX can find the position of that symbol so the email can be split into different parts.
SELECT
Email,
CHARINDEX('@', Email) AS AtPosition
FROM Employees;
CHARINDEX is useful for parsing emails, addresses, codes, reference numbers, and other structured text in SQL Server.
- CHARINDEX searches for text within another string.
- It returns the starting position.
- It is commonly used in SQL Server.
- It can help parse structured text.
- Other database systems may use different functions.
What does CHARINDEX do?
CHARINDEX returns the starting position of a specified expression inside another string in SQL Server.
Where can CHARINDEX be useful?
It is useful for locating delimiters or specific text when parsing emails, codes, and other structured strings.