charindex

Description

Returns an integer representing the starting position of an expression.

Syntax

charindex(expression1, expression2)

Parameters

expression

is a binary or character column name, variable or constant expression. Can be char, varchar, nchar, nvarchar, unichar or univarchar data, binary or varbinary.

Examples

Example 1

Returns the position at which the character expression “wonderful” begins in the notes column of the titles table:

select charindex("wonderful", notes) 
from titles 
where title_id = "TC3218"
-----------
        46

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute charindex.

See also

For general information about string functions, see “String functions”.

Function patindex