[英]Removing trailing spaces and whitespaces from SQL Server column
I have a column in my SQL Server database and it has white spaces from left and right site of the record. 我的SQL Server数据库中有一列,该记录的左右位置有空白。 Basically it's a nvarchar(250)
column. 基本上是nvarchar(250)
列。
I have tried removing white spaces completely like this: 我尝试完全像这样删除空白:
UPDATE MyTable
SET whitespacecolumn = LTRIM(RTRIM(whitespacecolumn))
But this didn't work out at all, the whitespace is still there. 但这根本没有解决,空格仍然存在。 What am I doing wrong here? 我在这里做错了什么?
I think replace is the way as you are looking to update 我认为替换是您寻求更新的方式
UPDATE MyTable SET whitespacecolumn = Replace(whitespacecolumn, ' ', '')
you can try doing select first and then prefer to update 您可以先尝试进行选择,然后再选择更新
SELECT *, Replace(whitespacecolumn, ' ', '') from MyTable
LTRIM, RTRIM will remove spaces in front and rear of column. LTRIM,RTRIM将删除列前后的空间。 In 2016 you can use TRIM function as below to trim special characters as well: 在2016年,您还可以使用以下TRIM函数修剪特殊字符:
SELECT TRIM( '.,! ' FROM '# test .') AS Result;
Output: 输出:
# test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.