CHARINDEX() function
The Charindex()
function supplies an integer value that represents the start of a substring within a string value
Syntax
charindex(substring,expr,[position])
Arguments
Argument | Data type | Description | Required? | Further information |
substring | string | Character or string to be identified in the input string | Yes | |
expr | string | Input string to search for substring | Yes | SQL expressions |
position | int | Position in expr to begin search for substring . | Optional | Defaults to 0 |
Returns
Data type | Value |
int | Position of substring in the expr input string. |
Examples
CREATE TABLE and INSERT data statements
create table customers
(_id id, segment string);
insert into customers(_id,segment)
values (1,'this is great')
CHARINDEX statement
select _id, charindex('is',segment) as charindex from customers;
Results:
CHARINDEX with starting from POSITION
select _id, charindex('is',segment,3) as charindex from customers;
RESULTS