简体   繁体   English

更改列中特定数据的任何方法,例如Mr to Dr包含名称

[英]Any way to change specific data in a column e.g Mr to Dr which contains a name

I am trying to change the Titles of 'doctors' in a database and was just wondering was there a SQL query which I could run to change them. 我试图更改数据库中“医生”的头衔,只是想知道是否存在可以用来更改它们的SQL查询。

The column im trying to change 我试图改变的专栏

What I am asking is that there is any way I can update the column to add a 'Dr' infront of the names to replace the 'Miss','Mr' etc. 我要问的是,有什么方法可以更新该列,以便在名称的前面添加一个“ Dr”以替换“ Miss”,“ Mr”等。

I'm thinking about using a SQL Statement containing the wildcard function to update it but not sure it would change the specifics. 我正在考虑使用包含通配符函数的SQL语句来更新它,但不确定是否会更改细节。

Thanks, 谢谢,

Karl 卡尔

Use REPLACE option 使用REPLACE选项

UPDATE table_name
SET column_name = REPLACE(column_name, 'Mr.', 'Dr.')
WHERE column_name LIKE 'Mr.%'

try this 尝试这个

Update myTable
set name = replace(replace(name,'Miss ','Dr '),'Mr ','Dr ')

I might suggest doing: 我可能建议您这样做:

update t
    set col = stuff(col, 1, charindex(' ', col + ' '), 'Dr');

This only replaces the first word in the string. 只会替换字符串中的第一个单词。 You might want to be extra careful and add a where clause. 您可能需要格外小心,并添加一个where子句。

update t
    set col = stuff(col, 1, charindex(' ', col + ' '), 'Dr') 
    where col like 'Miss %' or col like 'Mr %' or
          col like 'Mrs %' or col like 'Ms %';

The problem with replace() is that it replaces all occurrences in the string. replace()的问题在于它将替换字符串中的所有匹配项。 Although the honorifics are unlikely to be in a name, you could have names like "Missy Elliott". 尽管称呼不太可能使用名称,但是您可以使用“ Missy Elliott”之类的名称。

暂无
暂无

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

相关问题 我可以通过向后兼容的方式更改SQL Server表名吗? 例如添加一个永久别名? - Can I change a SQL Server table name in a way that is backwards compatible? E.g add a permanent alias? 如何创建存储过程以在 Sql server 中创建表,其中表的名称将按年份更改,例如 Order2019 - How to make a store procedure to create table in Sql server in which name of table will be changed by year e.g Order2019 SQL 相同姓氏的相同国家、相同姓名、相同年龄的人数(例如 smith) - SQL Count of same country, same name, same age for people with same last name (e.g smith) 如何通过值(例如-1)过滤SQL列并将表连接到另一个表 - How to filter a SQL column by a value e.g -1 and join the table to another table 如何将易碎数据(例如,连接字符串)从一个控制器传递到另一个 - How to pass fragile data e.g connection string from one controller to another 如何从oracle架构中包含该列名的所有表表中获取特定列的最大值? - How to get the max value for a specific column from all tables tables which contains that column name in an oracle schema? 如何在表中用逗号将小数点后的值更改为2,532.00到2532。 - How can i change value in decimal place with comma e.g 2,532.00 to 2532 in my table. 选择记录最大字符数的记录,例如“ A” - Select Record where Maximum Count of character e.g 'A' Rails,在最后一个之前找到对象,例如-1 - Rails, find object before last e.g -1 使用多个联接(例如,左联接) - Using multiple joins (e.g left join)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM