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.


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'

sql substring function example

Rate this post
Category: SQL Functions

About Ing. Jan Zedníček - BI Developer, Finance controller

My name is Jan Zedníček and I work as a BI Developer at Kentico Software in Brno. Mostly you can see me there working in the office, but I also work partly as a freelancer. I have been working as a freelancer for many companies for more than 5 years, but Kentico is the matter of my heart. I used to work as a financial controller at companies like Aero Vodochody, banking and I also used to be a bond program manager in Unicapital Investment group. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.