Using SUBSTRING
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

Using SUBSTRING

The SUBSTRING function returns part of either a character or binary string, or a text string, and takes the following parameters:

  • A character or binary string, a column name, or a string-valued expression that includes a column name.
  • The position at which the substring should start.
  • The length, in number of characters or in number of bytes for binary, of the string to be returned.

The following example displays the first initial and last name of each employee.

USE AdventureWorks;
GO
SELECT SUBSTRING(FirstName, 1, 1), LastName
FROM Person.Contact;
GO

The following example displays the second, third, and fourth characters of the string constant abcdef:

SELECT x = SUBSTRING('abcdef', 2, 3)

x

Here is the result set.

----------
bcd

(1 row(s) affected)
Show:
© 2016 Microsoft