Charindex TSQL Tutorial

Search an expression in an string expression and returns its starting position if found.

Charindex function syntax

charindex ( search_expression ,string_expression [ , start_location ] )

Charindex Example :

USE model;
GO
DECLARE @string varchar(64);

SELECT @string = 'My example';
SELECT CHARINDEX('y', @string) as 'Col_1',
CHARINDEX('x', @string) as 'Col_2',
CHARINDEX('le', @string,8) as 'Col_3';
GO

Result:

Col_1Col_2Col_3
259

See also: T-SQL Functions -> Concat -> Left -> Len -> Lower -> Ltrim