Versuchen Sie Folgendes:(Funktioniert wie erwartet)
declare @str varchar(500)
set @str = 'Good Good Good Good Good Good Good Good Luck Good GoodLuck MarkAndGood GoodMarkAnd MarkAndGood Good'
declare @replacedString varchar(500)
SET @replacedString = replace(@str,' Good ',' Better ')
SET @replacedString = replace(@replacedString,' Good ',' Better ')
SET @replacedString = CASE WHEN CHARINDEX('Good ', @replacedString) = 1 THEN
STUFF(@replacedString, 1, Len('Good'), 'Better')
ELSE @replacedString END
SELECT CASE WHEN CHARINDEX(REVERSE(' Good'), REVERSE(@replacedString)) = 1 THEN
Reverse(STUFF(Reverse(@replacedString), CHARINDEX(Reverse(' Good'),
Reverse(@replacedString)), Len(' Good'), Reverse(' Better')))
ELSE @replacedString END AS A
Eingabe:
Gut Viel Glück Gut Viel Glück Gut
Ergebnis:
Besser, besser, Glück, besser, viel Glück, besser