SQL Server database removes field cells, newline characters, carriage returns (using the Replace statement)

Source: Internet
Author: User

You can use the Replace function in SQL to replace certain characters in a field with the following syntax: Syntax replace (original-string, search-string, replace-string) parameter if one of the arguments is NULL , this function returns NULL. Original-string the string to be searched for. can be any length. Search-string the string to be searched for and replaced by Replace-string. The length of the string should not exceed 255 bytes. If Search-string is an empty string, the original string is returned as-is. Replace-string The string is used to replace the search-string. can be any length. If Replacement-string is an empty string, all occurrences of the search-string are deleted. Example: UPDATE tableName set Recordname=replace (Recordname, ' abc ', ' DDD ') replaces ABC in recordname field in table TableName with DDD One of the disadvantages of this function is that the substitution of the Text,ntext type field is not supported and can be implemented by the following statement: Update tableName set Recordname=replace (recordname as varchar (8000 ), ' abc ', ' DDD ')

2. NewLine characters in replace field, carriage return

1: Carriage return character

SELECT *, replace (detail, CHAR (+), ' <br> ') as displays the replaced content from Loginfo

2: Line break

SELECT *, replace (detail, CHAR (Ten), ' <br> ') as displays the replaced content from Loginfo

3: Return line break

SELECT *, replace (detail, char (+) + char (Ten), ' <br> ') as displays the replaced content from Loginfo

4: Replace carriage return line break to <BR><BR>

UPDATE loginfo SET detail = REPLACE (detail, char) + char (Ten), ' <br><br> ')

Note In the DOS \win series there will be a carriage return + newline character CHAR (10) +char

In UNIX \ Linux is a line break

Convert just remove the carriage return char (13).

The following SQL statement

UPDATE loginfo SET detail = REPLACE (detail, CHAR (13), ")

Replace the regular content

Update user_content Set [Address]=substring ([Address],1,patindex ('%<% ', [Address])-2) where PATINDEX ('%<% ', [ Address]) >2

SQL Server database removes field cells, newline characters, carriage returns (using the Replace statement)

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.