问题描述
我在 SQL Server 2008 数据库中有一个表.该表有一个名为名称"的 nvarchar(256) 列.不幸的是,该字段中的值包含额外的空格.例如,名称Bill"实际上在表中存储为Bill".
I have a table in a SQL Server 2008 database. This table has a nvarchar(256) column called 'Name'. Unfortunately, the values in this field have extra spaces included. For instance the name 'Bill' is actually stored as 'Bill ' in the table.
我想更新此表中的所有记录以删除多余的空格.然而,我惊讶地发现 SQL 没有 TRIM 函数.
I want to update all of the records in this table to remove the extra spaces. However, I was surprised to learn that SQL does not have a TRIM function.
如何一次更新所有记录以删除多余的空格?
How do I update all of the records at once to remove the extra spaces?
谢谢!
推荐答案
您确实有一个 RTRIM
和一个 LTRIM
函数.您可以将它们组合起来以获得您想要的修剪功能.
You do have an RTRIM
and an LTRIM
function. You can combine them to get the trim function you want.
UPDATE Table
SET Name = RTRIM(LTRIM(Name))
这篇关于在 SQL Server 2008 中修剪文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!