Beginner

318. CHARINDEX Function

Learn how SQL Server can locate a substring inside another string.

📘 Lesson 318 of 728 ⏱ 9 min 🎯 Intermediate

CHARINDEX is a SQL Server function that returns the starting position of a specified expression within another character expression.

CHARINDEX helps SQL Server users locate separators, symbols, and text patterns inside business fields.

Find the position of the @ symbol in an email address.

SQL
SELECT
    Email,
    CHARINDEX('@', Email) AS AtPosition
FROM Customers;

CHARINDEX is useful for text parsing, email processing, data validation, and extracting values from structured strings.

  • CHARINDEX searches for a substring.
  • It is commonly used in SQL Server.
  • It returns the starting position.
  • It is useful for text parsing.
  • It can be combined with SUBSTRING.
What does CHARINDEX do?

CHARINDEX returns the starting position of a specified substring within another string in SQL Server.

How can CHARINDEX and SUBSTRING work together?

CHARINDEX can locate a delimiter or starting point, while SUBSTRING can extract the required text around that position.

Have you finished this lesson?

Introduction to SQL – All Lessons