如何在SQL Server中删除字符串的空格 [英] How to remove blank space of a string in SQL server

查看:163
本文介绍了如何在SQL Server中删除字符串的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表中有一个名为Remarks的列,最后有一个空格。我用过LTRIM,RTRIM&替换功能。这不是在开玩笑。建议任何其他方式删除空白区域。



我尝试过:



In my table having a column named Remarks there is a blank space at the end. I used LTRIM,RTRIM & Replace function. It's not woking. Suggest any other ways to remove the blank space.

What I have tried:

update TableName set Remarks= LTRIM(RTRIM(Remarks)) 
update TableName set Remarks= replace(Remarks,' ','')

推荐答案

正如我在问题的评论中提到的那样,它可能是一个回车符或行尾符号。



找出字符串末尾的char类型的唯一方法是使用 ASCII 函数,它返回ASCII码值。



As i mentioned in the comment to the question, it might be a carriage return or end of line sign.

The only way to find out what kind of char is at the end of string, is to use ASCII function, which return the ASCII code value.

SELECT ASCII(RIGHT(Remarks, 1)) AS LastCharAsciiCode
FROM TableName





现在,当你知道那里有什么样的字符时,你可以更新你的表格!< br $>






你可以替换所有不需要的字符



Now, when you know what kind of char is there, you can update your table!

Or

You can replace all unwanted chars

update TableName set Remarks= REPLACE(REPLACE(REPLACE(Remarks,' ',''), CHR(10), ''), CHR(13), '')





祝你好运!



Good luck!


这篇关于如何在SQL Server中删除字符串的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆