SELECT a.id,a.name,
dm=CASE b.dm
WHEN 1 THEN '财务科'
WHEN 2 THEN '办公室'
WHEN 3 THEN '业务科'
END
FROM tba AS a
JOIN tbb AS b
ON a.id=b.id;
dm=CASE b.dm
WHEN 1 THEN '财务科'
WHEN 2 THEN '办公室'
WHEN 3 THEN '业务科'
END
FROM tba AS a
JOIN tbb AS b
ON a.id=b.id;
update a
set [name]=(case dm when 1 then '财务科' when 2 then '办公室' when 3 then '业务科' else '' end)+[name]
from tablea a inner join tableb b on a.id=b.id
SET Name=Name+b.Dept
FROM A表 a,
(
SELECT id,Dept=CASE WHEN dm=1 THEN '财务科'
WHEN dm=2 THEN '办公室'
WHEN dm=3 THEN '业务科'
ELSE ''
END
FROM B表
) b
WHERE a.id=b.id
where a.id=b.id啊?
dm=(CASE b.dm
WHEN 1 THEN '财务科'
WHEN 2 THEN '办公室'
WHEN 3 THEN '业务科'
END)+ a.name
FROM tba AS a
JOIN tbb AS b
ON a.id=b.id;
[name]=(case b.dm when 1 then '财务科' when 2 then '办公室' else '业务科' end)+a.name
from tablea a join tableb b on a.id=b.id
declare @a表 table (id varchar(3),name varchar(4))
insert into @a表
select '001','张三' union all
select '002','李四' union all
select '002','王二' union all
select '006','董六' union all
select '005','钱五' union all
select '006','赵大'
--> 测试数据: @b表
declare @b表 table (id varchar(3),dm int)
insert into @b表
select '001',1 union all
select '002',2 union all
select '003',3 union all
select '004',2 union all
select '005',2 union all
select '006',1
select a.id,name=case b.dm when 1 then '财务科' when 2 then '办公室' else '业务科' end+name from @a表 a left join @b表 b on a.id=b.id