RIGHT FUNCTION IN SQL SERVER 2005

The RIGHT function retrieves the portion of the string counting from the right. For example:

SELECT * FROM Employee

OUTPUT
_________________

1    Pawan    180000
2    Gaurav    80000
3    Saurabh    80000
4    Pawan    830000
5    Neelam    80000

SELECT RIGHT ( EMPNAME , 2) AS ‘RIGHT TWO CHARACTERS OF EMPNAME’ FROM Employee

OUTPUT
_________________

RIGHT TWO CHARACTERS OF EMPNAME

an
av
bh
an
am

SELECT RIGHT ( EMPNAME , NULL ) AS ‘RIGHT TWO CHARACTERS OF EMPNAME’  FROM Employee

OUTPUT — It will give you NULL 5 times
______________________________________
RIGHT TWO CHARACTERS OF EMPNAME

NULL
NULL
NULL
NULL
NULL

SELECT RIGHT ( NULL , 2 ) AS ‘RIGHT TWO CHARACTERS OF EMPNAME’  FROM Employee

OUTPUT — It will give you NULL 5 times
______________________________________
RIGHT TWO CHARACTERS OF EMPNAME

NULL
NULL
NULL
NULL
NULL

SELECT RIGHT ( NULL , 10 ) AS ‘RIGHT TWO CHARACTERS OF EMPNAME’

OUTPUT
______________________________________

NULL

Pawan Kumar
Pawankkmr@hotmail.com

Advertisements