请问UPDATE语句如何关联两个表?
MS SQLSERVER 7.0
如有A,B两个表,
A :字段cust_id,cust_name
B :字段cust_id,cust_name
如何用一个UPDATE语句关联字段cust_id把A中cust_name改为相对应的B表中的cust_name?
记得在ORACLE里是可以的,MSSQL里就不知道怎么写了,这种情况只能用游标来处理吗?
update a set a.cust_name=b.cust_name from a
join b
on a.cust_id=b.cust_id
ORACLE下应该是:
update A表 a
set cust_name=(select b.cust_name from B表 b where b.cust_id=a.cust_id)
where exists (select 1 from B表 b where b.cust_id=a.cust_id);
'cust_name='处应该还可以支持多个字段,如(cust_name,cust_sex)=(select b.cust_name,b.cust_sex from ...