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?
Jr software developer trainee
Myself Ashutosh Kumar Verma from Varanasi. I am a Software Developer in MindStick Software pvt. ltd. Prayagraj. I have completed my MCA from VBSP. University, Jaunpur in 2021.
SUBSTRING() 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.