Table of Contents
Substring in SQL Server: SUBSTRING Function in SQL Server is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
The article will explore and guide you how to use the SUBSTRING function in SQL Server to extract a substring from a specified string.
Describe
The SUBSTRING function in SQL Server allows you to extract a substring of the specified length starting from a position in the input string.
Syntax
To use the SUBSTRING function in SQL Server, we use the following syntax:
SUBSTRING(string, start, length)
Parameters :
- string: can be a string, variable or column you want to extract.
- start: is an integer specifying the location where the substring starts to be returned. Note that the first character in the string is 1, not 0.
- The SUBSTRING function can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.
For instance,
Take a look and explore some examples of SUBSTRING functions in SQL Server.
SELECT SUBSTRING('Tipsmake.com', 1, 4);Result: 'Quan'SELECT SUBSTRING('Tipsmake.com', 5, 3);Result: 'Tri'SELECT SUBSTRING('Tipsmake.com', 5, 15);Result: 'TriMang.com'
Previous lesson: STUFF function in SQL Server
Next lesson: UPPER function in SQL Server
FAQ
What should you know about describe?
The SUBSTRING function in SQL Server allows you to extract a substring of the specified length starting from a position in the input string.
What should you know about syntax?
To use the SUBSTRING function in SQL Server, we use the following syntax:
What should you know about for instance,?
Take a look and explore some examples of SUBSTRING functions in SQL Server.
Reader Comments 0
Sign in with email or Google to join the discussion.