Friday, 10 August 2018

SQL Server String function

1.Length :Len function calculate string length. It take string as argument and return numeric number.

Example
SELECT [Data]=LEN('Hellow World')

Output
12


2.Left :LEFT function return specific number of character from string from its left.It takes string as argument and integer as number of string to be return from left.
  
Example  
SELECT [Data]=LEFT ('Hellow World', 5)

Output
Hello

3.Right :Right function return specific number of character from string from its right.It takes string as argument and integer as number of string to be return from right.
  
 
Example 
SELECT [Data]=RIGHT ('Hellow World', 5)

Output
World

4.Ltrim : Ltrim function remove leading blanks from a string.It takes string as argument and return string after removing the leading blank.
 
Example 
SELECT [Data]=LTRIM(' Hellow World ')

Output
Hellow World    



5.Rtrim :  Rtrim function remove leading blanks from a string.It takes string as argument and return string after removing the leading blank.

Example 
SELECT [Data]=RTRIM(' Hellow World ')

Output
'  Hellow World '


6.Substring : Substring function returning a specific number of character from string.It takes string as argument and starting as argument and length as argument. It return string from starting position to specific number of character.
Example 
SELECT [Data]=SUBSTRING('Hellow World', 1, 5)

Output
Hello

7.Replace : Replace function replace some specific string with another string. Replace functions take string as argument, string to be replaced as another argument, string to replace as another argument. Function return string by replacingsecond string with third string.

 
Example 
SELECT [Data]=REPLACE('Hellow World','World','SQL Server')

Output
Hellow SQL Server


8.STUFF :Stuff function insert one string within another string.

Example 
SELECT [Data]=STUFF('Hellow World',7, 8, 'SQL Server')

Output
HellowSQL Server



9.UPPER : Upper function converts a string to upper-case.
Example 
SELECT [Data]=UPPER('Hellow World')

Output
HELLOW WORLD

10.LOWER :Lower function converts a string to lower-case.

Example 
SELECT [Data]=LOWER('Hellow World')

Output
hellow world

11.SPACE :SPACE function returns a string with a specified number of spaces.

Example 
SELECT [Data]='Hellow'+SPACE(10)+'World'

Output
Hellow          World

12.Replicate :Replicate is used to repeat the existing string for given number of times. 

Example 
SELECT [Data]=REPLICATE('0', 4)

Output
0000

13.CHARINDEX :CHARINDEX performs a case-insensitive search, if substring is not found within string, the CHARINDEX function will return 0.

Example 
SELECT [Data]=CHARINDEX('w', 'Hellow World')

Output
6

14.
Example 
SELECT [Data]=STR(185.476, 6, 2)

Output
185.48

15.
Example 
SELECT [Data]=QUOTENAME('Hellow World')  

Output
[Hellow World]
16.REVERSE :Reverse a string.

Example 
SELECT [Data]=REVERSE('Hellow World')

Output 
dlroW wolleH 

No comments:

Post a Comment

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

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