且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不替换子字符串的情况下替换句子中的特定单词

更新时间:2023-11-15 14:46:16

您可以尝试以下查询。

You can try the following query. Here at the start and end a space has been inserted first and then removed that space.

DECLARE @i VARCHAR(250)
SET @i = 'MR JOHN NAMR is working from 3 days.'

SELECT rtrim(ltrim(Replace(replace(' '+@i+' ',' MR ','  '),
' MR ','  ')))

输出如下所示


JOHN NAMR从3天开始工作。

JOHN NAMR is working from 3 days.

您可以找到实时演示 Demo Replace Word

You can find the live demo Demo Replace Word