SQL string de-whitespace workaround

Source: Internet
Author: User

The reason for a string with a space in a table

1, spaces are spaces.

2, data is fetched from other systems, files, imported into SQL Server table, because the source data there is a special character display space.

Second, the solution

In the first case, the processing of the whitespace is relatively simple, and Replace (column, ', ') can be solved.

In the second case, the solution is more troublesome: you need to find the appropriate ASCII code, and then replace (Column,char (ASCII), ") to solve, the following is a chestnut:

CREATE TABLE #temp (NAME NVARCHAR) INSERT into #temp Select ' Tomorrow is National Day ' +char  --line break SELECT * from #temp                      -- The end is displayed as a space select replace (NAME, ' ', ') from #temp   --To not go away this space select replace (Name,char), ') from #temp  -- Remove the space select  Replace (Name,char (name,1)) from #temp   --If you do not know what character is the last, first turn the ASCII code in the replacement drop TABLE #temp----Below is the result of the query:-' Tomorrow is the National Day '--' Tomorrow is the National Day '--' Tomorrow is the National Day '--' Tomorrow is the National Day '

  

SQL string de-whitespace workaround

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.