在 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
关于sql - 删除所有空格并将 SQL 中的多行合并为单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46225232/