0% found this document useful (0 votes)
40 views2 pages

CHARINDEX (Transact-SQL) : Syntax Arguments

CHARINDEX is a Transact-SQL function that searches for one character expression inside another and returns the starting position if found. It takes in an expression to find, an expression to search, and optionally a start location. It returns an integer representing the starting position or NULL if either expression is NULL. It performs comparisons based on collation and returns 0 if the expression is not found.

Uploaded by

Uyuyu Opera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

CHARINDEX (Transact-SQL) : Syntax Arguments

CHARINDEX is a Transact-SQL function that searches for one character expression inside another and returns the starting position if found. It takes in an expression to find, an expression to search, and optionally a start location. It returns an integer representing the starting position or NULL if either expression is NULL. It performs comparisons based on collation and returns 0 if the expression is not found.

Uploaded by

Uyuyu Opera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CHARINDEX (Transact-SQL)

 07/24/2017
 3 minutes to read

o

 
o

 
o

 
o

 
o

 
o +6

APPLIES TO:  SQL Server  Azure SQL Database  Azure Synapse Analytics
(SQL DW)  Parallel Data Warehouse

This function searches for one character expression inside a second character
expression, returning the starting position of the first expression if found.

 Transact-SQL Syntax Conventions

Syntax
SQLCopy
CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )

Arguments
expressionToFind
A character expression containing the sequence to find. expressionToFind has an
8000 character limit.

expressionToSearch
A character expression to search.
start_location
An integer or bigint expression at which the search starts. If start_location is not
specified, has a negative value, or has a zero (0) value, the search starts at the
beginning of expressionToSearch.

Return types
bigint if expressionToSearch has an nvarchar(max), varbinary(max),
or varchar(max) data type; int otherwise.

Remarks
If either the expressionToFind or expressionToSearch expression has a Unicode data
type (nchar or nvarchar), and the other expression does not, the CHARINDEX
function converts that other expression to a Unicode data type. CHARINDEX cannot
be used with image, ntext, or text data types.

If either the expressionToFind or expressionToSearch expression has a NULL value,


CHARINDEX returns NULL.

If CHARINDEX does not find expressionToFind within expressionToSearch,


CHARINDEX returns 0.

CHARINDEX performs comparisons based on the input collation. To perform a


comparison in a specified collation, use COLLATE to apply an explicit collation to
the input.

The starting position returned is 1-based, not 0-based.

0x0000 (char(0)) is an undefined character in Windows collations and cannot be


included in CHARINDEX.

You might also like