Showing posts with label space. Show all posts
Showing posts with label space. Show all posts

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

concatenation

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/*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 slo para quitarle los espacios.|||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)