Substring Example In Sql. In the following example, the substring() function is used on the firstname column of the employee table to return a substring with 4 characters. Select substring('my sql tutorial', 4, 3) as part try it live.

The syntax of substring function is shown in the following example. Right(‘sql server’,4) can be written as substring(‘sql server’,7,4) which says to start at the 7 th position and then return the next four characters. Sql substring function can be used with any string value wrapped in single or double quotes or the string values stored in the variables of type varchar and even on the values of the columns that store string values, binary, text format values, and images.