Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL, Remove space in string

Tags:

replace

tsql

I have two strings in SQL and the REPLACE function only works on one of them, why is that?

Example 1:

SELECT REPLACE('18 286.74', ' ', '')

Example 2:

SELECT REPLACE('z z', ' ', '')

Example 1's output is still "18 286.74" whereas Example 2's output is "zz". Why does SQL not react the same way to both strings?

UPDATE:

When running select replace('123 123.12', ' ', '') that works fine, still not with '18 286.74'.

like image 757
StevenMcD Avatar asked Aug 24 '09 12:08

StevenMcD


1 Answers

Test it the following way.

select unicode(substring('18 286.74', 3, 1))

If the code returns 32 then it's a space, if not, it's a different Unicode character and your replace ' ' won't work.

like image 146
Jabezz Avatar answered Sep 28 '22 18:09

Jabezz