因为派生表 'm' 包含聚合,或 DISTINCT 或 GROUP BY 子句,或 PIVOT 或 UNPIVOT 运算符,所以不可更新。
哪位大神帮忙看下。
SQL语句如下:
update m set m.FEntrySelfB0168 = rn.FPrice, m.FEntrySelfB0169 = rn.FPrice * n.fQty
from (
select n.FDetailID,MAX(rn.FDetailID) FRKDetailID,m.FDate,n.FEntrySelfB0168,n.FEntrySelfB0169,n.FQty
from ICStockBill m
left join ICStockBillEntry n on m.FInterID=n.FInterID
left join ICStockBillEntry rn on n.FItemID =rn.FItemID --产品入库明细
join ICStockBill r on rn.FInterID=r.FInterID and r.FTranType=2 and m.FDate >=r.FDate --产品入库表头
where m.FTranType=21
group by n.FDetailID,m.FDate,n.FEntrySelfB0168,n.FEntrySelfB0169,n.FQty
) m left join ICStockBillEntry rn on m.FRKDetailID=rn.FDetailID
where rn.FPrice <>0 and (isnull(rn.FPrice,0)<>isnull(m.FEntrySelfB0168,0)
or isnull(m.FEntrySelfB0169,0)<>m.fqty* isnull(m.FEntrySelfB0168,0))
and CONVERT(varchar(10), m.FDate, 120) >= '2020-06'
and CONVERT(varchar(10), m.FDate, 120) >= '2020-07-01'
and CONVERT(varchar(10), m.FDate, 120) <= '2020-07-04'