Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Returns the starting position of the specified expression in a character string.
Syntax
CHARINDEX ( expression1 , expression2 [ , start_location ] )
Arguments
expression1
An expression that contains the sequence of characters to be found. The expression1 argument is an expression of the ntexttype 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.
Return Value
int
Code Example
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