如何使用 MS SQL Server Management Studio 删除 SQL 数据库表中的前导空白空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14501440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:17:02  来源:igfitidea点击:

How to delete leading empty space in a SQL Database Table using MS SQL Server Management Studio

sqlsql-server

提问by andalusi

I imported an Excel sheet with countries into a database table.

我将带有国家/地区的 Excel 工作表导入到数据库表中。

Unfortunately all rows have some leading empty space.

不幸的是,所有行都有一些领先的空白空间。

So, how can I delete these empty spaces?

那么,如何删除这些空白空间?

回答by xQbert

This will remove leading and trailing spaces

这将删除前导和尾随空格

Update tablename set fieldName = ltrim(rtrim(fieldName));

some versions of SQL Support

某些版本的 SQL 支持

Update tablename set fieldName = trim(fieldName);

If you just want to remove leading

如果您只想删除前导

update tablename set fieldName = LTRIM(fieldName);