![](/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.