Tuesday 19 March 2013

Use of String function in Sql Server


Use of String Function in SQL Server
SQL Server support string function which is Already defined. Following are some important string function and their uses:-
       1.       Char (ASCII code)
This function returns the The character which is equivalent to particular ASCII code which you will pass too This function.
For Example:-
Select char (66);
This function will Return B.
      2.       ASCII (Char)
This function Returns the ASCII code which is equivalent to particular char which you will Pass to this function.
For example:-
Select ASCII ('B');
this function will return 66
     3.       Len(char)
This function returns the length of string which you will pass to len function. It returns integer value.
For Example:-
select LEN('isha malhotra');
this function will return 13
  4.  Left(char, number of char)
This function will returns the number of char from left.
For example:-
select LEFT('isha malhotra',3);
this function will return ish.

  5.  right(char, number of char)
This function will returns the number of char from right.
For example:-
select right('isha malhotra',3);
this function will return tra.
  6.  Lower(char)
This function will returns the char in lower which you will pass to this function.
For example:-
select LOWER('ISHA');
This function will return isha.
  7.  Upper(char)
This function will returns the char in Upper which you will pass to this function.
For example:-
select upper('isha');
This function will return ISHA.

    8.       Rtrim(char)
This function will trim the spaces from right.
For example:-
select RTRIM('   isha   ');
this function will return ‘   isha
    9.       Ltrim(char)
This function will trim the spaces from left.
For example:-
select LTRIM('   isha   ');
this function will returnisha  ’
   10.   Substring(char,position,no_of_char)
This function will returns characters from position which you will pass.
For exampl:-
select SUBSTRING('isha malhotra',2,3);
in this functin it will pick 3 char from 2nd position. This functin will return sha.

There are many more string functions but these are which usually I used in my projects.


No comments:

Post a Comment