Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display full name by combining first name+last name with space between first name and last name. I tried the following code.
declare @sql varchar(1000)
set @sql='select tblUsers.strFirstName'+ '+' +'tblUsers.strLastName as ''fullName'' from tblUsers'
exec(@sql)


But I am getting output as TonyIssac without space between two words. How can I achieve this?
Posted
Updated 22-Nov-10 18:57pm
v2

1 solution

Try:
SQL
-- Name with a space  
set @sql='select tblUsers.strFirstName'+ '+' +  ' ' +  '+' + 'tblUsers.strLastName as ''fullName'' from tblUsers'

OR
SQL
-- Name with a comma 
 
set @sql='select tblUsers.strFirstName'+ '+' +  ',' +  '+' + 'tblUsers.strLastName as ''fullName'' from tblUsers'
 
Share this answer
 
Comments
JF2015 23-Nov-10 1:19am    
Good one.
deepak thomas 23-Nov-10 1:43am    
not getting space between words.
deepak thomas 23-Nov-10 2:54am    
got space between words when i wrote like this
set @sql='select tblUsers.strFirstName'+ '+' + ''' ''' + '+' + 'tblUsers.strLastName as ''fullName'' from tblUsers'
deepak thomas 23-Nov-10 2:55am    
thanks

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