Sunday, February 12, 2012

concatenation with space

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
ShubhangiHi,

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|||Hi,

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

Quote:

Originally Posted by Senthil

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

|||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

No comments:

Post a Comment