Beginner

103. CHARINDEX Function

Learn how to find the position of one text value inside another using CHARINDEX.

📘 Lesson 103 of 728 ⏱ 8 min 🎯 Intermediate

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons