What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?
What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?
33310-Nov-2021
Updated on 10-Nov-2021
Home / DeveloperSection / Forums / What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?
What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?
Steilla Mitchel
10-Nov-2021SUBSTRING() in SQL:
The SUBSTRING() function is returns a part of given string or we can say this function is extract some characters from given string.
Syntax – SUBSTRING(String, start, Length);
Example-
CHARINDEX() in SQL:
CHARINDEX() function is searches for a substring from String and returns the position or index number of particular substring from given String. If substring is not found then it returns 0.
Syntax- CHARINDEX(substring, string, start);
Start is optional in CHARINDEX() function.
Example-
In the following SQL statement the start number is provide where the searching is start. By default the starting position is 1.