Thursday, March 7, 2013

SQL Server SUBSTRING Function

In this post , I will explain the SUBSTRING function of SQL Server of string functions category.
In my previous posts, I explained UPPER Function, STUFF Function, LEN Function, UNICODE Function, LEFT Function, CHARINDEX Function, CHAR Function, ASCII Function and some other articles related to SQL Server.

Here, I am going to explain SUBSTRING function of SQL Server.

SUBSTRING() Function

This function is used to get the part of the character, binary, text or image expression.
 
Syntax- SUBSTRING(expression, start, length)
Arguments-
  • expression : An expression of character string, binary string, text.
  • start : An integer value which specified the start position of substring.
  • length : An positive integer value which specified how many characters or bytes of the expression will be returned.If length is negative, an error is occurred.
Return Type- Returns character data if expression is one of the supported character data types. Returns binary data if expression is one of the supported binary data types.


Example-
 
Declare @nstring varchar(50)
set @nstring='Dot Net World'
select SubString(@nstring, 2,6)
--OutPut ot Net

Declare @nstring varchar(50)
set @nstring='Dot Net World'
select SubString(@nstring, 3,5)
--OutPut t Net

1 comment:

  1. Great post. All readers will definitely like this post. Looking forward for your next post.

    ReplyDelete

^ Scroll to Top