![](/img/trans.png)
[英]How do I update a column in 3rd row the same as a column in 2nd row in MySQL?
[英]How to update the 2nd and 3rd character in string with X
我有一个雇员表,其中有名字和姓氏列。 我需要掩盖数据。 我需要用X替换第二个和第三个字符。
update employee
set last_name =
Stuff(last_name, CharIndex(LEFT(last_name,1), last_name), Len(LEFT(last_name,1)), 'X')
from Employee where Employee_Id = 'A.Abrahams'
更新不起作用。 可以帮忙吗? 提前致谢。
您可以尝试以下方法:
update employee
set last_name = stuff(last_name, 2, 2, 'XX')
where Employee_Id = 'A.Abrahams'
如果您只需要替换位置2和3,那么为什么不使用以下内容:
update employee
set last_name = Stuff(last_name, 2, 2, 'X')
where ...
-- 'Abrahams' --> 'AXahams'
如果要屏蔽除第一个和最后一个字符以外的所有内容,这可能会起作用:
update employee
set last_name = Stuff(last_name, 2, len(last_name)-2, 'X')
where len(last_name) > 2
and ...
-- 'Abrahams' --> 'AXs'
-- 'Doe' --> 'DXe'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.