Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SUBSTRING

SQL Server 2000

Returns part of a character, binary, text, or image expression.

Syntax
SUBSTRING ( expression , start , length ) 
Arguments
expression
Is a character string, binary string, text, image, a column, or an expression that includes a column. Do not use expressions that include aggregate functions.
start
Is an integer, or an expression that can be implicitly converted to int, that specifies where the substring begins.
length
Is an integer, or an expression that can be implicitly converted to int, that specifies the length of the substring (the number of characters or bytes to return).
Return Types

Returns character data if expression is one of the supported character data types. Returns binary data if expression is one of the supported binary data types.

The returned string is the same type as the given expression with the exceptions shown in the following table.

Given expression Return type
image varbinary
ntext nvarchar
Examples

The following example uses the Employees table in the Northwind database. The example returns the initial of the employees' first names and the employees' last names.

SELECT SUBTRING(FirstName,1,1) AS Initial, LastName
FROM Employees

This is the result set:

Initial..........LastName
-------------------------
A................Fuller
M................Peacock
L................Callahan
N................Davolio
J................LeverLing
S................Buchanan
M................Suyama
R................King
A................Dodsworth


Show:
© 2015 Microsoft