--清除在已在銷售中消化,使用校正後又重新插入的資料
drop table pcje2007
select lsh,pcrq,xmbm,ph,sqys,sqyje,bqss,bqsje,bqfs,bqfje,jcs,pcs,sqyje+bqsje-bqfje+(dslsj*(pcs-jcs)) as pcje,round(PCS*DSLSJ,2) AS PCJE2 into pcje2007 from zy_yp1_pcb where datediff(mm,pcrq,'2007-01-01')=0
delete from pcje2007 where sqys=0 and bqss=0 and bqfs=0 and jcs=0 and pcs=0
select a.pcrq,b.pcrq,a.xmbm,a.ph,a.sqyje,b.pcje,B.PCJE2 from zy_yp1_pcb a,pcje2007 b where datediff(mm,a.pcrq,'2007-2-01')=0 and a.xmbm=b.xmbm and a.ph=b.ph and ABS(a.sqyje-b.pcje2)>0
select * into pcb200701 from zy_yp1_pcb
update zy_yp1_pcb set sqyje=B.PCJE2 from zy_yp1_pcb a,pcje2007 b where datediff(mm,a.pcrq,'2007-1-01')=0 and a.xmbm=b.xmbm and a.ph=b.ph and ABS(a.sqyje-b.pcje2)>0
SELECT * FROM ZY_SYS2_YPZDK WHERE GBM='11097570'
update zy_yp1_pcb set dslsj=round((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end)),4) from zy_yp1_pcb where abs((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end))-dslsj)>1 and datediff(mm,pcrq,'2007-2-01')=0 and round((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end)),4)<>0
select xmbm,dslsj,round((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end)),4) from zy_yp1_pcb where abs((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end))-dslsj)>1 and datediff(mm,pcrq,'2007-2-01')=0 and round((sqyje+bqsje)/((case (sqys+bqss) when 0 then 1 else sqys+bqss end)),4)<>0