SQL Server CHARINDEX() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server CHARINDEX() Function

❮ SQL Server Functions

Example

Search for "t" in string "Customer", and return position:

SELECT CHARINDEX('t', 'Customer') AS MatchPosition;
Try it Yourself »

Definition and Usage

The CHARINDEX() function returns the location of a substring in a string.

Syntax

CHARINDEX(substring, string, start_pos)

Parameter Values

Parameter Description
substring Required. The substring to find
string Required. The string to search in
start_pos Optional. The position in string where the search will start. The first position is 1

Note

  • CHARINDEX() performs a case-insensitive search
  • If substring is not found within string, the CHARINDEX function will return 0

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

Search for "OM" in string "Customer", and return position:

SELECT CHARINDEX('OM', 'Customer') AS MatchPosition;
Try it Yourself »

Example

Search for "mer" in string "Customer", and return position (start in position 3):

SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;
Try it Yourself »

❮ SQL Server Functions