日期:2014-05-16 浏览次数:21067 次
/* ycfj_bp_1与ycfj_bp内容相同.共有43259条记录.
*/
WHILE EXISTS ( select id from ycfj_bp_1)
BEGIN
set @ia=@ia+1
SELECT top 1 @pbppf=部品品番,@bpsl=部品数量,@jhrq=交货日期,@id=id FROM ycfj_bp_1
select @pdsl=实盘数量,@idd=id from cp_hbpd where 部品品番=@pbppf
if @pdsl<0
begin
print '小余0第:'+cast(@ia as varchar(10))
if exists(select id from ycfj_bp where id>@id and 部品品番=@pbppf)
begin
delete ycfj_bp where id>@id and 部品品番=@pbppf
end
end else begin
print '大余0第:'+cast(@ia as varchar(10))
if exists(select id from ycfj_bp where id=@id)
begin
--扣除在库
select @pdsl_1=实盘数量 from cp_hbpd_1 where 部品品番=@pbppf--盘点数量
select @ylhsl=实盘数量 from cp_ylsl where 部品品番=@pbppf--已来料数量.
update ycfj_bp set 盘点数量=@pdsl_1,盘点剩余=(@pdsl-@bpsl),在库日期=@jhrq,在库数量=(@pdsl-@bpsl),
已来料=@ylhsl
where id=@id
update cp_hbpd set 实盘数量=实盘数量-@bpsl where id=@idd
end
end
delete from ycfj_bp_1 where [id] = @Id
END