TechNet
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize
This documentation is archived and is not being maintained.

CHARINDEX (SQL Server Compact Edition)

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


CHARINDEX ( expression1 , expression2 [ , start_location ] ) 

expression1

An expression that contains the sequence of characters to be found. The expression1 argument is an expression of the ntext type or a data type that can be implicitly converted to nvarchar.

expression2

An expression that is typically a column searched for the specified sequence. The expression2 argument is an expression of the ntext type or a data type that can be implicitly converted to nvarchar.

start_location

The character position from which 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. The start_location argument can be tinyint, smallint, int, or bigint.

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

SELECT [Last Name], CHARINDEX('an', [Last Name]) AS Position
FROM Employees

This is the result set:

Last Name..............Position
------------------------------
Davolio           0
Fuller            0
Leverling         0
Peacock           0
Buchanan          5
Suyama            0
King              0
Callahan          7
Dodsworth         0
Hellstern         0
Smith            0
Patterson         0
Brid              0
Martin            0
Pereira           0
Show:
© 2016 Microsoft