COALESCE Function
COALESCE function returns the first Non NULL value
If the Employee has got the First Name, return first name
If the Employee doesn’t have a First Name and he has a Middle and a Last Name, then return Middle Name.
If the Employee doesn’t have First Name and Middle Name and he has only the Last Name, then return LastName
But if an Employee has both First Name and Middle Name, then return First Name.
Similarly, if an Employee has all of the Names –
First, Middle and Last Names, then return FirstName
So the priority should first go to First Name, then to Middle Name and finally to Last Name.
Now, i want the output to be as
SELECT EmpID ,COALESCE(FirstName,MiddleName,LastName) AS Name,Designation,Salary
FROM employee
No comments:
Post a Comment
Thank you for visiting my blog