Remove spaces from SQL, and remove spaces from SQL

Source: Internet
Author: User

Remove spaces from SQL, and remove spaces from SQL

 

I. Problem description:

The data stored in the nvarchar field in the database is as follows:

'3' * 10'

 

Ii. solution:

-- Test Case
Create table # temp
(Name nvarchar (20) null)
Insert into # temp select FecalColiform from WaterQuality
Select * from # temp

Update # temp set Name = replace (Name, '',''); --- 1
Update # temp set Name = replace (Name, '',''); --- 2
Update # temp set Name = replace (Name, '',''); --- 3
Update # temp set Name = replace (Name, '',''); --- 4

-- The result is valid.

-- Practical project application

Update WaterQuality set FecalColiform = replace (FecalColiform, '',''); --- 1
Update WaterQuality set FecalColiform = replace (FecalColiform, '',''); --- 2
Update WaterQuality set FecalColiform = replace (FecalColiform, '',''); --- 3
Update WaterQuality set FecalColiform = replace (FecalColiform, '',''); --- 4

 

You may have a question: why is the same operation repeated ??

A: ''It looks the same and actually different.

You need to completely copy the column and select all to check whether the concave and convex statuses behind them are empty.

Then copy the space that has not been modified and modify it.

For example, copy and put it in single quotes to observe '2. 0 × 10', then copy its unique '', and then execute a modification.

Before modification:

After modification:

 

Iii. failure experience:

1. trim Method

Select ltrim ('000000×10') -- remove spaces on the left
Select rtrim ('3. 3 × 10') -- remove spaces on the right.
Select ltrim (rtrim ('1970, 3.3 × 10') -- removes spaces at the beginning and end.

The result is valid.

But the actual data is like this '3. 3 × 10'

Select ltrim (rtrim ('3. 3 × 10') -- remove spaces at the beginning and end

The result is invalid.

 

References:

Https://zhidao.baidu.com/question/183968041.html

Https://www.cnblogs.com/TurboWay/p/5924445.html

 

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.