By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,026 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

P: 24
Hi,

I have previously posted but the reply given didn't solve my purpose.
Please check & revert.

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+
2 Replies


P: 4
/*Solo:*/
select (rtrim(EM.FIRST_NAME) + ' ' + rtrim(EM.LAST_NAME)) as pendejo from employee em

--Utilizando una variable:
declare @x varchar(200)
set @x = 'select (rtrim(casefunctionality) + '' '' + rtrim(casename)) as mames from employee em'
exec (@x)

El problema es que le debes de poner doble comilla simple.

El RTrim es sólo para quitarle los espacios.
Oct 6 '06 #2

P: 1
Hi,
The following code will solve your problem
instead of two single quotes use four single quotes to concatnate two fields
-------------------------------------------------------------
declare @str1 varchar(8000)
set @str1=('select EM.EMPLOYEE_ID,EM.FIRST_NAME+'' ''+EM.LAST_NAME as EMPLOYEENAME from EMPLOYEE_MASTER EM')
print @str1
exec (@str1)
Oct 7 '06 #3

Post your reply

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