SQL Server database table field values have spaces, how to remove spaces (such as char (5) when the data is less than 5 bits when SQL Server automatically fill the blanks)

Source: Internet
Author: User
Tags rtrim
Normal spaces

Before and after spaces, use LTrim and RTrim, for example: LTrim (RTrim (Name))

Middle space, replace with replace function, for example: replace (Name, ' ', ')

If it is an ordinary space, it is easy to replace, but sometimes encounter some special spaces, it is more troublesome, it looks like the ordinary space, but it is unable to replace. This requires a special way to find the space and replace it with replace.

To find such a space, you need to use the ASCII function, through the ASCII function, find out the ASCII value of the space, and then replace with the Replace function +char function.

For example, using the ASCII function to find the ASCII value of a space is 9, replace with replace (Name,char (9), ').

In the way above, it is just how to find the ASCII value of the space.

Suppose name has a value of "Zhang San", followed by a special space.

Select ASCII (replace (name, ' Zhang San ', ') from table name where id=**

Take the value of name and replace it with the text, and the extra space will be the ASCII function to get the space ASCII value.

SQL Server database table field values have spaces, how to remove spaces (such as char (5) when the data is less than 5 bits when SQL Server automatically fill the blanks)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.