SQL Replace tab, carriage return, line feed, and leading and trailing spaces

Source: Internet
Author: User
SQL Replace tab, carriage return, line feed, and leading and trailing spaces

When you recently bulk-repairing your data, you need to import large amounts of data using Excel. The data provided by the customer is not standardized, most of the data rows have tabs, carriage returns, and exchange characters, and I need to take the data first.
The usual method is to replace the corresponding symbol with replace, and you can define a function that merges them together.

The specific code is as follows:

--去除空格fn_trimcreate function fn_trim(@str nvarchar(max))returns nvarchar(max)BEGIN    --char(9) 水平制表符    --char(10)换行键    --char(13)回车键    return  LTRIM(RTRIM((replace(replace(replace(@str,char(9),‘‘),char(10),‘‘),char(13),‘‘))));end

SQL Replace tab, carriage return, line feed, and leading and trailing spaces

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.