LEFT FUNCTION IN SQL SERVER 2005

SQL SERVER 2005 supports retrieving portions of the string.
To retrieve the first few characters from the left of the string you use the LEFT function.

Example:

SELECT * FROM Employee

OUTPUT
_________________

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

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

OUTPUT
_________________

LEFT TWO CHARACTERS OF EMPNAME

Pa
Ga
Sa
Pa
Ne

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

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

NULL
NULL
NULL
NULL
NULL

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

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

NULL
NULL
NULL
NULL
NULL

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

OUTPUT — It will give you only one NULL Value
______________________________________
LEFT TWO CHARACTERS OF EMPNAME

NULL

Pawan Kumar
Pawankkmr@hotmail.com

Advertisements