Because it does not give the sum of names in MySQL

2

I have the following:

CREATE Table apellidos_completo (Completo varchar (255))

INSERT INTO apellidos_completo (Completo )values ('alvarez')

UPDATE apellidos_completo set Completo =  'Rodriguez' + Completo 

I do SELECT

SELECT *
FROM apellidos_completo 

the result should be

'Rodriguez Alvarez'

However, the result obtained is:

(0) osea CERO

NOTE: if I do it in SQL server if it works, fine, but in MySQL it does not work out.

    
asked by Juan Carlos Villamizar Alvarez 30.06.2018 в 05:02
source

1 answer

5

The union, not the sum; is done by means of the function CONCAT() , which helps me concatenate or join several values, guide yourself by this example

SET @varUno = 'Pack';
SET @varDos = ' nombre';


MariaDB [(none)]> SELECT CONCAT(@varUno, @varDos) AS Mensaje;
+-------------+
| Mensaje     |
+-------------+
| Pack nombre |
+-------------+
  

This function, need inside and separated by commas the values   that you want to join, finally with an alias we give a temporary name to   the table that has to show me the results

Within your code you return 0 because you are taking or trying to take the values as those that you can add by using the + sign, since it is not of a numeric type it returns 0

In any case, what you are looking for is not the sum of the text strings, but the concatenation of them that is very different

    
answered by 30.06.2018 / 05:06
source