Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

SUBSTRING

Example

Retrieve 3 characters from a string, starting at position 1.

SELECT SUBSTRING(‘SQL Tutorial’13AS ExtractString;

Definition and Usage

The SUBSTRING() function retrieves a specified number of characters from a string.

Syntax

SUBSTRING(stringstartlength)

Parameter Values

Parameter

Description

string

Required: Specifies the string from which to extract characters.

start

Required: Specifies the starting position for extraction, where the first position in the string is numbered 1.

length

Required: Specifies the number of characters to extract from the string. This value must be positive.

Technical Details

Works in:

 SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Retrieve 5 characters from the “CustomerName” column, starting at position 1.

SELECT SUBSTRING(CustomerName, 15AS ExtractString
FROM Customers;

Example

Retrieve 100 characters from a string, starting at position 1.

SELECT SUBSTRING(‘SQL Tutorial’1100AS ExtractString;