在 SQL Server 2014 中删除字符串中所有空格的最佳方法是什么?
我的字符串是:
Maximize your productivity for building engaging,
beautiful web mapping applications
尝试删除字符串之间的 Enter 和 Tab 空格以及单词之间的 1 个空格。结果应该是这样的:
Maximize your productivity for building engaging, beautiful web mapping applications
您可以使用replace()
,但这有点棘手:
select replace(replace(replace(replace(replace(col, ' ', '<>'
), '
', '<>'
), ' ', '<>' -- tab goes here
), '><', ''
), '<>', ' '
)
from t;
这个想法是将空格替换为<>
,那么所有><
s 被删除,只留下一个。例如:
a b c -- original data with three spaces and one space
a<><><>b<>c -- after replacing spaces with <>
a<>b<>c -- after removing ><
a b c -- after replacing <> with a space
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)