Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a Employee details in my database their name are given in the
field(firstname,middlename,lastname). when i try to fetch the employee details by their name .

Select * From Employeedetails where
Concat(firstname,'',middlename,'',lastname)='Maria Francis Desosa'

It Works Fine

When i try to fetch Employee who does not have middle name it return zero. so i try


Select * From Employeedetails where
Concat(IFNULL(ER.firstname,' '),' ',IFNULL(ER.middlename,''),'',IFNULL(ER.lastname,'')
='Maria Desosa'

Still this not getting the data. can any body know how to retrieve the data who does not have middlename

Thanks
parithi
Posted

1 solution

Below Query works in MS SQL 2012. You will have convert it appropriately in MySQL -

SQL
SELECT CONCAT(FirstName,CASE WHEN ISNULL(MiddleName,'')='' THEN '' ELSE ' ' + MiddleName END, ' ',LastName) FROM CustomerMaster
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900