Substring with variable : SUBSTRING « String Functions « SQL Server / T-SQL Tutorial






4> DECLARE @FullName VarChar(25)
5> SET @FullName = 'George Washington'
6> SELECT SUBSTRING(@FullName, 4, 6)
7> GO

------
rge Wa

(1 rows affected)








12.22.SUBSTRING
12.22.1.SUBSTRING is used to retrieve part of a string from another string. The syntax for the function is as follows:
12.22.2.Returning a Chunk of an Expression
12.22.3.Substring with variable
12.22.4.SUBSTRING(FullName, CHARINDEX(' ', FullName) + 1, LEN(FullName))
12.22.5.select SUBSTRING('(559) 555-1212', 7, 8)
12.22.6.Return first name
12.22.7.Get the last name
12.22.8.A SELECT statement that uses the LEFT, RIGHT, and SUBSTRING functions