Tuesday, 17 July 2018

Sql Server SUBSTRING


SUBSTRING a return part of a string. SUBSTRING is used to get a part of a  string from the original string. SUBSTRING not only work on string or text data, SUBSTRING work on binary or image data also. SUBSTRING always return a part of string , text , binary or image data which was supplied to it.Here is the list of data type that support SUBSTRING

1)char2)varchar3)text4)nchar5)nvarchar6)ntext7)binary8)varbinary9)image
If you supply a binary data type to the SUBSTRING, SUBSTRINGreturn binary, if you supply sting, SUBSTRINGwill return string. The same scenario happen for text , image data also.

Syntax :

SUBSTRING ( stringn ,start_position , length ) 

string : The source string on which SUBSTRING will be applied.
start_position :  The position , from where start extraction.
length : The number of characters to be extracted. 


Below are the example of SUBSTRING from different position to different length. The data supplied is string and return also string.


Example 1

SELECT SUBSTRING('Hellow World',8,5)
Result: World

Example 2 

SELECT SUBSTRING('Hellow World',0,6)
Result: Hello

Example 3 

SELECT SUBSTRING('Hellow World',7,1)
Result: ''

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...