Click to Rate and Give Feedback
TechNet
TechNet Library
SQL Server
SQL Server 2008
 CHARINDEX (SQL Server Compact)

  Switch on low bandwidth view
Other versions are also available for the following:
SQL Server Compact 3.5 Service Pack 1 Books Online
CHARINDEX (SQL Server Compact)

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.

int

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
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker