update b set b.fprice=c.fprice , b.fauxprice=c.fprice , b.FAmount=b.FQty*b.FPrice
from icstockbillentry b
inner join icstockbill a on a.FInterID=b.FInterID
inner join
( select distinct b.FItemID,b.finterid,b.FPrice
from ICStockBillEntry b
inner join (
select FItemID,max(b.finterid)finterid from icstockbillentry a
inner join icstockbill b on a.finterid=b.finterid
where b.ftrantype =2 and FPrice <>0 and b.fdate<'2018-08-01'
group by FItemID
) a on b.finterid =a.finterid and a.FItemID=b.FItemID )c on c.FItemID= b.fitemid
where a.ftrantype=2 /*and fprice=0*/ and b.FAmount=0
//更新追加了一个金额b.FAmount=b.FQty*b.FPrice,因为没有金额自制入库核算可能还是没有单价
//步骤1:先根据条件fprice=0先把单价更新上,在把这个注销,更新金额
/* icstockbillentry 出入库单据分录表(单据体)
fprice 单价
auxprice 辅助单价
icstockbill 出入库单据表(单据头)
ftrantype 单据类型
*/