样本数据
create table MyTable
(
Task nvarchar(50)
);
insert into MyTable (Task) values
('VLV LOADING/RELEASE 1st DS'),
('VLV LOADING/RELEASE 2nd DS'),
('VLV LOADING/RELEASE 3rd DS'),
('VLV LOADING/RELEASE 1st DS'),
('VLV LOADING/RELEASE 2nd DS'),
('VLV LOADING/RELEASE 3rd DS');
解决方案
选项 1
使用case 表达式。
select case mt.Task
when 'VLV LOADING/RELEASE 1st DS' then 'Proximal Release Force-S'
when 'VLV LOADING/RELEASE 2nd DS' then 'Proximal Release Force-L'
when 'VLV LOADING/RELEASE 3rd DS' then 'Proximal Release Force-M'
end as Task
from MyTable mt;
选项 2
如果替换值在另一个表中可用,则使用join。
create table Task
(
Id int,
Task nvarchar(50),
Description nvarchar(50)
);
insert into Task (Id, Task, Description) values
(10, 'VLV LOADING/RELEASE 1st DS', 'Proximal Release Force-S'),
(11, 'VLV LOADING/RELEASE 2nd DS', 'Proximal Release Force-M'),
(12, 'VLV LOADING/RELEASE 3rd DS', 'Proximal Release Force-L');
select t.Description as Task
from MyTable mt
join Task t
on t.Task = mt.Task;
结果
Task
------------------------
Proximal Release Force-S
Proximal Release Force-M
Proximal Release Force-L
Proximal Release Force-S
Proximal Release Force-M
Proximal Release Force-L
Fiddle 了解实际情况。