SQL SUBSTRING Function – Get Part of String With Example

SUBSTRING function is used in sql to select part of text string in text. This function belongs to the group of text functions – string functions. I created a big summary of T-SQL text functions – you can find it here.

SQL SUBSTRING Syntax

SELECT SUBSTRING(text, <start position of the text character>, <the number of characters to get from the starting point>)

The function has 3 arguments:

  • field with text where we select the text
  • starting position – numeral position of the character in text from which we will select its part
  • number of characters from the starting position

Example of the SUBSTRING Function

DECLARE @TEXT AS VARCHAR(100) = '.gerge.OPGKER/The text we want to get/ FWG--efwER'
SELECT SUBSTRING(@TEXT,15,23)

sql substring function example

5/5 - (1 vote)
Category: SQL Functions

About Ing. Jan Zedníček - Data Engineer & Controlling

My name is Jan Zednicek, and I have been working as a freelance Data Engineer for roughly 10 years. During this time, I have been publishing case studies and technical guides on this website, targeting professionals, students, and enthusiasts interested in Data Engineering particularly on Microsoft technologies as well as corporate finance and reporting solutions. 🔥 If you found this article helpful, please share it or mention me on your website or Community forum

Leave a Reply

Your email address will not be published. Required fields are marked *