Replace strings that start and end with certain strings

I need to replace certain string in a table column named "Description" with many rows. One of the descriptions in a row may look like this:

Apple iPhone 12 64GB for AT&T. Includes SIM card and USB charging cable, no other accessories. Cosmetic condition: good, with few minor marks or scratches.

I need to replace the string from "Includes" to "accessories" with another string, so it will look like this:

Apple iPhone 12 64GB for AT&T. Includes phone only. Cosmetic condition: good, with few minor marks or scratches.

Because the words between "Includes" and "accessories" may be different among the rows so I cannot use an exact phrase to match and replace. The substrings I want to replace always starts with "Includes" and end with "accessories" so I must use those words as reference to replace them. Please advise.

I tried

Update Descriptions
SET Description = REPLACE (Description, ***, ***)

but couldn't figure out what to place in ***

Something like this should do it:

UPDATE D
SET Description = STUFF(Description, includes_start + LEN('includes'), accessories_start + LEN('accessories') - includes_start - LEN('includes'), ' phone only')
--SELECT Description, STUFF(Description, includes_start + LEN('includes'), accessories_start + LEN('accessories') - includes_start - LEN('includes'), ' phone only') AS new_description
FROM #Descriptions D
CROSS APPLY (
    SELECT CHARINDEX('Includes', Description) AS includes_start
) AS ca1
CROSS APPLY (
    SELECT CHARINDEX('accessories', Description, includes_start + LEN('Includes')) AS accessories_start
) AS ca2
WHERE Description LIKE '%includes%accessories%'
1 Like

I will give it a try. Thanks