CHARINDEX doen't allow to search for pattern specific string

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 225
CHARINDEX string function is used to find out the starting position of an expression/string/character in another expression/string.

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


--CHARINDEX()---FIRST OCCURANCE OF STRING
SELECT CHARINDEX('first', 'CHARINDEX is used to find out the first occurance of a string')

OUTPUT:
35

It doesn't allow you to search for partial string or pattern... For instance, is you wish to search for the pattern...

Example:
SELECT CHARINDEX('wild%search', 'CHARINDEX does not support wild card characters to search for pattens')

Output
0


Actually, the pattern wild%search is found in the given expression, but the above CHARINDEX returns 0 as starting position. It will treat wild card characters as normal one; searches for the character '%' in the given string..

Comments or Responses

Login to post response