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