表A
ID,PriceA,PriceB
表B
ItemID,priceA,priceB
如何根据表B的price更新表A的相应字段。(条件是A.ID=B.ItemID)
例如:
A:1,1.3,1.5
B:1,0.2,0.3
更新后为:
A:1,1.5,1.8
ID,PriceA,PriceB
表B
ItemID,priceA,priceB
如何根据表B的price更新表A的相应字段。(条件是A.ID=B.ItemID)
例如:
A:1,1.3,1.5
B:1,0.2,0.3
更新后为:
A:1,1.5,1.8
update A set priceA=(select priceA from B where A.id=B.Itemid);sqlserver:update A set priceA= b1.priceA,priceB=b1.priceB
from A a1,B b1 where a1.id=b1.Itemid;
update A set priceA= b1.priceA + a1.priceA ,priceB=b1.priceB + a1.priceB
from A a1,B b1 where a1.id=b1.Itemid;
create trigger upd_tr
on b
for update
as
begin
update a set a.pricea = a.pricea+ inserted.prica
where a.id = inserted.id
insert A(id,value) values(1,1)
create table B(id int,value int)
insert B(id,value)
select 1,1 union all
select 1,2 union all
select 1,3
update A set value=a.value + b.value from a,b where a.id=b.id
select * from b
select * from a
go