Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to join first name & last name in my sql
this is my sql :
select concat(FirstName,' ',LastName) as fullname from tablename;
but if last name is blank,then i am getting null as fullname..
but in that case i want first name ,,,how to do this??
Posted
Updated 31-Jan-14 21:22pm
v2

Try select concat(ISNULL(FirstName,''),' ',ISNULL(LastName,'')).
ISNULL[^] will check for null and return a value accordingly.
 
Share this answer
 
Comments
Member 10276220 1-Feb-14 3:51am    
its not working...getting the error...
"Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IS NULL(FirstName,''),' ',IS NULL(LastName,'')) as fullname from keyinformation ' at line 1"
Abhinav S 1-Feb-14 3:55am    
Oops. Its mySQl.
mySQL is slightly different.

Try IFNULL() instead of ISNULL().

Please mark as answered if it works.
Member 10276220 1-Feb-14 4:48am    
thanx
Abhinav S 1-Feb-14 7:45am    
Please mark this answer as the right answer if it works. Thanks.
Try this.
SQL
select (Isnull(@fname,' ')+''+Isnull(@lastname,' ') ) as fullname ;  
 
Share this answer
 
try This
select Trim(FirstName + ' ' + LastName) as fullname from tablename;

Or
select Trim(FirstName & ' ' & LastName) as fullname from tablename;

I am not sure about the '+' and '&', so try both and this will fulfill your need.
 
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