使用通配符更新

Update with wildcard

需要像这样更新所有具有子字符串的行: 'forcestartpage=xx'并替换为 'forcestartpage=18' * 子串前后有很多字符不应该改变

试过了,没用:

update t_reminderscont
set body = REPLACE (body,'forcestartpage=__','forcestartpage=18')

谢谢

您可以使用 STUFF 函数:

SELECT
    T.body,
    Replaced = STUFF(
        T.Body,                                 -- Insert in T.Body
        CHARINDEX('forcestartpage=', T.Body),   -- ... at the position where 'forcestartpage=' starts
        LEN('forcestartpage=18'),               -- ... while replacing 17 characters
        'forcestartpage=18')                    -- ... the value forcestartpage=18
FROM
    YourTable AS T
WHERE
    T.body LIKE '%forcestartpage=__%' AND
    T.body NOT LIKE '%forcestartpage=18%'

然而,这仅适用于每行中 forcestartpage= 的首次出现。