Simply replace it;
(只需更换它;)
SELECT REPLACE(fld_or_variable, ' ', '')
Edit: Just to clarify;
(编辑:只是为了澄清;)
its a global replace, there is no need to trim()
or worry about multiple spaces for either char
or varchar
: (它是一个全局替换,不需要trim()
或担心char
或varchar
多个空格:)
create table #t (
c char(8),
v varchar(8))
insert #t (c, v) values
('a a' , 'a a' ),
('a a ' , 'a a ' ),
(' a a' , ' a a' ),
(' a a ', ' a a ')
select
'"' + c + '"' [IN], '"' + replace(c, ' ', '') + '"' [OUT]
from #t
union all select
'"' + v + '"', '"' + replace(v, ' ', '') + '"'
from #t
Result
(结果)
IN OUT
===================
"a a " "aa"
"a a " "aa"
" a a " "aa"
" a a " "aa"
"a a" "aa"
"a a " "aa"
" a a" "aa"
" a a " "aa"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…