I'm having difficulty with a T-SQL query that joins 2 tables using a character column. I suspect that there are some whitespace differences causing the problem but have not been able to track them down. In order to test this theory I'd like to strip all of the whitespaces from the joining columns and see if that resolves the issue. Unfortunately, I'm stuck on how to remove all whitespaces in a T-SQL string. Here is a simple example showing what I've tried (see the test columns):
select
str,
test1 = replace(str, '\\s+' , ''),
test2 = replace(str, '[\s]*' , '')
from
(
values
(''),
(' '),
(' xyz'),
('abc '),
('hello world')
) d (str);
Is there a way to get this to work in T-SQL?
Clarification: by white space, I mean to strip out ALL of the following:
\s white space (space, \r, \n, \t, \v, \f)
' ' space
\t (horizontal) tab
\v vertical tab
\b backspace
\r carriage return
\n newline
\f form feed
\u00a0 non-breaking space
