CHARINDEX

Returns the position of the specified character or sequence. Zero (0) is returned if the string given as search parameter does not exist. The optional start_position parameter specifies the position in the string to start searching.

Syntax:

CHARINDEX (string_to_search, search_for [,start_position])

Example:

/* returns 3 as it is the first occurrence of the character 'c' in the string */ 
SELECT CHARINDEX ('abcda1234', 'c')

/* returns 5 as the first occurrence of 'a' on or after position 2 is on position 5 in the string */
SELECT CHARINDEX ('abcda1234','a',2)

/* returns 0 as the character does exist in the string */
SELECT CHARINDEX ('abcda1234','x')
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.