Remove space from concatenated string fields in MySQL

I have 3 fields that I concatenate and it works very well in my query, but I cannot decide how to remove the space from the merged data in the concat field.

TRIM(CONCAT(c.data1,c.data2)) AS concat_done 

Result:

 concat_done 33 0250S 0450E 028NW 
+4
source share
4 answers

instead

 TRIM(CONCAT(c.data1,c.data2)) AS concat_done 

try

 REPLACE(CONCAT(c.data1,c.data2), ' ', '') AS concat_done 
+4
source

add REPLACE call:

 REPLACE(TRIM(etc...), ' ', '') ^--one space ^-- no spaces 
+4
source

First of all, you should probably show your input as well as your output.

Secondly, trim () removes leading and trailing spaces , so you want concat(trim(var1), trim(var2)) instead of trimming the concatenated version, which now has internal spaces.

update: Or, as other answers say, just use replace (). But thatโ€™s why trim () didnโ€™t work the way you wanted.

+3
source

UPDATE Table_1 set Column_1 = TRIM (Replace (replace (replace) (Column_1, '\ t', ''), '\ n', ''), '\ r', ''));

You can also use a large replacement in an internal replacement.

0
source

Source: https://habr.com/ru/post/1400695/


All Articles