Replace the content in the text field in SQL

Source: Internet
Author: User

At that time, I could not write it myself. Later I searched for the materials and made a series of tests based on what others wrote. I found many bugs. Later I wrote them again:

Declare @ ID int // pass an ID
Declare @ str1 varchar (100), @ str2 varchar (100)
Declare @ I int, @ Len int
Declare @ ptrval binary (16)
Set @ ID = 5
Set @ str1 = 'aaa' // Search Text
Set @ str2 = 'tb' // Replace the content
Set @ Len = Len (@ str1)
While 1 = 1
Begin
Select @ I = patindex ('%' + @ str1 + '%', pagecontent) from DBO. t_customhtmleditorpage where menuid = @ ID
If @ I> 0
Begin
Set @ I = @ I-1
SELECT @ ptrval = TEXTPTR (PageContent) FROM T_CustomHTMLEditorPage WHERE MenuId = @ Id
UPDATETEXT T_CustomHTMLEditorPage.PageContent @ ptrval @ I @ len @ str2 // update the queried Field
SELECT @ I = patindex ('%' + @ str1 + '%', PageContent) from T_CustomHTMLEditorPage WHERE MenuId = @ Id
End
Else
Break
End

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.