表结构:
create table SalePlan
(
PlanId int identity(1,1) primary key,
GoodsId int,
PlanPrice decimal(18,2)
);
go
create table Goods
(
GoodsId int identity(1,1) primary key,
Price decimal(18,2)
);
go
原始数据:
insert into Goods(Price)
values(100);
insert into Goods(Price)
values(200);
insert into Goods(Price)
values(300);
insert into Goods(Price)
values(400);
insert into Goods(Price)
values(500);
go
insert into SalePlan
values(1,0);
insert into SalePlan
values(2,0);
insert into SalePlan
values(3,0);
insert into SalePlan
values(4,0);
insert into SalePlan
values(5,0);
go
一条语句将销售计划的销售金额修改为商品表的价格:
update s set s.PlanPrice = g.Price from SalePlan s,Goods g where s.GoodsId = g.GoodsId;
go
最终结果:
完成.