update b set b.fprice=c.fprice , b.fauxprice=c.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<‘2017-01-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 b.fprice=0
/* icstockbillentry 出入库单据分录表(单据体)
fprice 单价
auxprice 辅助单价
icstockbill 出入库单据表(单据头)
ftrantype 单据类型
*/