用不同列的字符串替换单元格中的部分字符串



我想用同一表中使用的列中的值替换单元格中的字符串。

字符串表示"your bonus is bonus_score",我希望用"bonus_score"列中的数据替换'bonus score'语句。

表格结构:

person_id nvarchar (8), 
first_name nvarchar(100), 
lastname nvarchar(100), 
text nvarchar(max), 
text_modified nvarchar(max), 
bonus_score decimal(10,2)

编辑:O错误地解决了这个问题:这里的目的是获得自动解决方案,该解决方案将检测"text"中的字符串是否包含表中不同列的任何名称,并自动替换中的数据。

您可以使用updatereplace():

update t
set text_modified = replace('bonus_score', bonus_score)
where text_modified like '%bonus_score%';

类似的内容。这将用奖金分数列中的值替换text_nvarchar列中的字符串"bonus_score"。

update tTable
set text_modified=replace(text_nvarchar, 'bonus_score', bonus_score);

最新更新