简体   繁体   English

用来自不同列的字符串替换单元格内的部分字符串

[英]Replacing part of string within cell with string from different column

I want to replace string within a cell with value from the column that is used in the same table .我想用同一个表中使用的列中的值替换单元格中的字符串。

String says "your bonus is bonus_score" and I want to have 'bonus score' statement replaced with data from "bonus_score" column.字符串说"your bonus is bonus_score" ,我想用"bonus_score"列中的数据替换'bonus score'语句。

Table structure:表结构:

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

EDIT: O have wrongly addressed the question: the aim here is to obtain automatic solution that will detect if string within 'text'contains any name of different columns within the table and automatically replace data within.编辑:O 错误地解决了这个问题:这里的目的是获得自动解决方案,该解决方案将检测“文本”中的字符串是否包含表中不同列的任何名称并自动替换其中的数据。

You can use update and replace() :您可以使用updatereplace()

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

Something like this.像这样的东西。 This replaces the string 'bonus_score' within the text_nvarchar column with the value from the bonus score column.这会将 text_nvarchar 列中的字符串 'bonus_score' 替换为来自奖励分数列的值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM