4

I am trying to concatenate two strings having space between them.The script below concatenates but it doesn't give any space between them.

UPDATE INS  
set INS.UpdateBy = x.FNameTxt +''+''+''+ x.LNameTxt 
From #Insured INS
Inner Join 
(
select I.ModSystemUserId,SU.FNameTxt,SU.LNameTxt
from Insured I
inner join dbo.SystemUser SU
on I.ModSystemUserId = Su.SystemUserId
where I.InsuredId = @insuredId
) AS X
on INS.Insuredid =@insuredId 

I am doing this INS.UpdateBy = x.FNameTxt +''+''+''+ x.LNameTxt

x.FNameTx = John
x.LNameTxt = Doe

result: JohnDoe i need space between them

Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
JuniorDev
  • 193
  • 1
  • 2
  • 13
  • 1
    on mysql you have to use [CONCAT](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat) function – Jorge Campos Jan 02 '14 at 20:37
  • "*The script below concatenates...*" - no it doesn't: the [`+`](http://dev.mysql.com/doc/en/arithmetic-functions.html#operator_plus) operator does not perform string concatenation in SQL. – eggyal Jan 02 '14 at 20:38
  • [Valid MySQL operators](http://dev.mysql.com/doc/refman/5.0/en/non-typed-operators.html) and [MySQL string functions](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html) – Michael Berkowski Jan 02 '14 at 20:40
  • 1
    @JorgeCampos: Not *entirely* true - one *can* also use `||` if the [`PIPES_AS_CONCAT`](http://dev.mysql.com/doc/en/server-sql-mode.html#sqlmode_pipes_as_concat) SQL mode is enabled. – eggyal Jan 02 '14 at 20:49

1 Answers1

9

Try this

UPDATE INS  
  set INS.UpdateBy = CONCAT(x.FNameTxt,'  ',x.LNameTxt) ....

CONCAT(str1,str2,...)

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118