Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

SQL SUBSTRING Function

SUBSTRING extracts part of a string, binary, text, or image value.

The start and length parameters are specified as number of characters for character data types and bytes for binary data types

Example

#

This example returns part of a string that is 3 characters long.

SELECT SUBSTRING('My SQL Tutorial', 4, 3) AS Part
Result:  1 record
Part
SQL

Syntax

Syntax for the SUBSTRING function.

SUBSTRING (string, start, length)

string -- a string value or a column name.

start -- marks the position where the extraction will begin.

length -- specifies how many characters to extract from the string.


More Examples

SUBSTRING.

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: List customers with first initials and last name.
SELECT SUBSTRING(FirstName, 1, 1) + '. ' + 
       LastName AS Name,
       City, Country
  FROM Customer
Result:  91 records
Name City Country
M. Anders Berlin Germany
A. Trujillo México D.F. Mexico
A. Moreno México D.F. Mexico
T. Hardy London UK
C. Berglund Luleå Sweden
H. Moos Mannheim Germany

You may also like



Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides


vsn 3.1