Export (0) Print
Expand All

CHARINDEX

SQL Server 2000

Returns the starting position of the specified expression in a character string.

Syntax
CHARINDEX ( expression1 , expression2 [ , start_location ] ) 
Arguments
expression1
Is an expression containing the sequence of characters to be found. expression1 is an expression of the ntext type or a data type that can be implicitly converted to nvarchar.
expression2
Is an expression, usually a column searched for the specified sequence. expression2 is an expression of the ntext type or a data type that can be implicitly converted to nvarchar.
start_location
Is the character position to start searching for expression1 in expression2. If start_location is not given, is a negative number, or is 0, the search starts at the beginning of expression2. start_location can be tinyint, smallint, int, or bigint.
Return Types

int

Examples

The following example searches for the expression 'an' from the last names of the employees in the Northwind database.

SELECT LastName, CHARINDEX('an', LastName) AS Position
FROM Employees

This is the result set:

LastName..............Position
------------------------------
Fuller................0
Peacock...............0
Callahan..............7
Davolio...............0
Leverling.............0
Buchanan..............5
Suyama................0
King..................0
Dodsworth.............0

Show:
© 2015 Microsoft