SUBSTRING (SQL Server Compact)

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

Syntax

SUBSTRING ( expression, start, length ) 

Arguments

  • expression
    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
    An integer or an expression that can be implicitly converted to int, which specifies where the substring begins.

  • length
    An integer or an expression that can be implicitly converted to int, which specifies the length of the substring.

Return Value

Returns character data if expressionis one of the supported character data types. Returns binary data if expressionis one of the supported binary data types. If start = 1, then the substring begins from the first character of the expression.

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

Code Example

The following example returns the initial of the first name and the full last name for each employee in the Employees table.

SELECT SUBSTRING([First Name],1,1) AS Initial, [Last Name]
FROM Employees

This is the result set:

Initial            Last Name
----------------------------
N           Davolio
A           Fuller
J           Leverling
M           Peacock
S           Buchanan
M           Suyama
R           King
L           Callahan
A           Dodsworth
A           Hellstern
T           Smith
C           Patterson
J           Brid
X           Martin
L           Pereira
(15 rows affected)