By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

concatenation with space

P: 24
Hi,

I am unable to concat 2 fields with a space between them in sql query.
I want to write my query in following fashion only as there are many conditions which I concat. Thus I am using variable @sql_st and not the direct sql statement.

Following query works perfect
DECLARE @SQL_ST VARCHAR(8000)
set @SQL_ST = 'SELECT EM.EMPLOYEE_ID,
(EM.FIRST_NAME + EM.LAST_NAME) as emp_name from employee_master em'
execute (@SQL_ST)

but when modified to get space between first & last name of employee I get an error
DECLARE @SQL_ST VARCHAR(8000)
set @SQL_ST = 'SELECT EM.EMPLOYEE_ID,
(EM.FIRST_NAME + ' ' + EM.LAST_NAME) as emp_name from employee_master em'
execute (@SQL_ST)

Pls reply ASAP.

Thanks
Shubhangi
Sep 26 '06 #1
Share this Question
Share on Google+
3 Replies


P: 10
Hi,

USE the below...

DECLARE @SQL_ST VARCHAR(8000)
set @SQL_ST = 'SELECT EM.EMPLOYEE_ID,
(EM.FIRST_NAME + ' + ' ' + 'EM.LAST_NAME) as emp_name from employee_master em'
execute (@SQL_ST)

Cheers,
Sharmila
Sep 26 '06 #2

P: 24
Hi,

Space doesn't appears between first & last name using the below query.
please reply.

Hi,

USE the below...

DECLARE @SQL_ST VARCHAR(8000)
set @SQL_ST = 'SELECT EM.EMPLOYEE_ID,
(EM.FIRST_NAME + ' + ' ' + 'EM.LAST_NAME) as emp_name from employee_master em'
execute (@SQL_ST)

Cheers,
Sharmila
Sep 26 '06 #3

P: 10
Hi,


Sorry Please use like this..

DECLARE @SQL_ST VARCHAR(8000)
set @SQL_ST = 'SELECT EM.EMPLOYEE_ID,
(EM.FIRST_NAME + '' '' + ' + ' ' + 'EM.LAST_NAME) as emp_name from employee_master em'
print @SQL_ST


Regards,
Sharmila
Sep 28 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.