sqlserver有两张表A表
code name status
1 a 01
2 b 02
3 c 03B表
code status
1 01
2 01
3 01现想根据B表的status修改A表的status,都改成01,关联的字段是code,请问这样语句如何写?
code name status
1 a 01
2 b 02
3 c 03B表
code status
1 01
2 01
3 01现想根据B表的status修改A表的status,都改成01,关联的字段是code,请问这样语句如何写?
set
status=B.status
from
B
where
A.code=B.code
from a,b
where a.code= b.code
insert A select 1, 'a', '01'
union all select 2, 'b', '02'
union all select 3, 'c', '03'create table B(code int, status char(2))
insert B select 1, '01'
union all select 2, '01'
union all select 3, '01'update A set A.status=B.status
from B
where A.code=B.codeselect * from A--result
code name status
----------- ---- ------
1 a 01
2 b 01
3 c 01(3 row(s) affected)
update A
set A.status=B.status
from A,B
where A.code=B.code