Pages

Sunday, 9 June 2013

CHARINDEX() function in SQL.

CHARINDEX is a SQL function that searches an expression (char or string) in given expression and return start position if matches found. If matches not found it return 0.

Syntax:
CHARINDEX(Expressio1, Expression2, [Start_Location])
Where,
Expression1: String to be look for in expression2
Start_Location: It means from where to start looking for expression1 in expression2.

NOTE:
It returns bigint if expression2 is of verchar(max), nvarchar(max), varbinary(max) datatypes, else it returns int.

Example: