日期:2014-05-18  浏览次数:21058 次

求一个SQL(A表(id,qty),b表(id,qty)),要求:如A表中(ID)=B表中(ID),把B表中的(QTY)更新A表中的(QTU)
求一个SQL(A表(id,qty),b表(id,qty)),要求:如A表中(ID)=B表中(ID),把B表中的(QTY)更新A表中的(QTU)


------解决方案--------------------
update A set [qty]=(select qty from B where A.id=B.id)
------解决方案--------------------
update a set qtu=(select qty from b where a.id=b.id) where id in(select id from b)
------解决方案--------------------
应该为:

update A set [qty]=isnull((select qty from B where A.id=B.id),name)

刚刚少考虑了一种情况,当A表中的ID 在B表不存在的时候,会把A表中的qty的值置为NULL;

------解决方案--------------------
update A set qty = (select qty from B where B.Id = A.Id)