SQL SUBSTRING() functions extracts a substring with a specified length starting from a location in an input string.
SYNTAX
SUBSTRING (inputstring, startposition, length)
inputstring is the source string that extract the substring.
startpostion is the starting position where the substring begins. The first position of the string is 1.
length is the length of the substring.
Lets look at an example of SQL SUBSTRING() function in SQL.
DECLARE @stringtxt VARCHAR(20)= 'Microsoft Sql Server' SELECT SUBSTRING(@stringtxt, 1, 9) AS STRINGTXT
[Also Read SQL Server Charindex function]
It returns a substring starting at position 1 with the length 9.
Lets take one more example and try to get a substring ‘Sql Server’ from string ‘Microsoft Sql Server’
The following statement returns a substring starting at position 11 with the length 10.
DECLARE @stringtxt VARCHAR(20)= 'Microsoft Sql Server' SELECT SUBSTRING(@stringtxt, 11, 10) AS STRINGTXT

Also Read..