Methods for bulk substitution of strings in SQL Server

Source: Internet
Author: User

UPDATEMaindataSETContent=REPLACE(CAST(Content as VARCHAR(8000))        , 'XM00000137'        , 'XM00000078')WHERE [Key]inch(SELECTMd_key fromIndex_md_inprojectWHEREMd_inproject= 'XM00000137')

Using the Replace function, the format is:

Update [table name ] Set [Fields field name ] = Replace ([Fields field name ],' replaced original content ','  To be replaced by the content '

Of course, if the field type that you want to replace directly is the text type, it will be an error ("parameter data type text is invalid for parameter 1 of the Replace function").

Hashxu: A string operation cannot be performed on a query for data of type text or ntext.
the most used is to use text as a varchar (actual content length less than 8000 bytes) or ntext as nvarchar (actual content length less than 4000 bytes) to handle
Update Table Set Column = Replace (Cast(Columnasvarchar(8000)), ' Oldkeyword ',' newkeyword ') Update Table set Column=replace (Cast (Column as nvarchar (4000)), ' Oldkeyword ',' Newkeyword ')

Methods for bulk substitution of strings in SQL Server

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.