stringsqlString=" select "+string.Format(" {0} as Version , ",version)+" r1.ErpMaterialCode, r2.Price, r1.SumPrice , r1.MaterialDesc, (isnull(r2.Price,0)-isnull(r1.SumPrice,0)) as diffPrice from \n"+
"( select ErpMaterialCode, MaterialDesc, SUM(Price) as SumPrice from(\n"+
"select a.ErpMaterialCode, b.SettlementPartCode, a.MaterialDesc, (a.Qty * b.Price) as Price from\n"+
"(SELECT ErpMaterialCode, MaterialDesc, SettleMaterialCode, Qty, Version ,CustomerCode \n"+
" where mdetail.Version='{0}' and mdetail.CustomerCode='{1}' \n"+
") a \n"+
"inner join Set_settlement_part b on a.Version = b.Version and a.SettleMaterialCode = b.SettlementPartCode and a.CustomerCode = b.CustomerCode) temp group by ErpMaterialCode, MaterialDesc) r1 left join set_pricelist r2 "+
" on r2.MaterialCode=r1.ErpMaterialCode and r2.Version='{0}'\n";
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount, --金额\n"+
" ISNULL( InvoicePrice * Qty, 0 ) AS SettleQty, --结算金额\n"+
" (Price-InvoicePrice) as InvoiceDiffPrice, --单价差异\n"+
" ISNULL( Price * Qty-InvoiceMoney, 0 ) AS SumDiffMoney --总金额差异\n"+
"FROM\n"+
" (\n"+
" SELECT\n"+
" c.WMSDeliveryNote,--交货单号\n"+
" c.WMSActualGoodsDate,--实际发货日期\n"+
" a.Kanban,--条码号\n"+
" b.MaterialCode SapMaterialCode,--厂内物料号\n"+
" b.MaterialDesc,--物料描述\n"+
" b.CustomerPartCode,--客户物料\n"+
" b.EstimateTypeDesc,--物料组(车型)\n"+
" c.WMSDeliveryQty,--交货数量\n"+
" a.Qty AS SettleNumber,--结算数量\n"+
" a.SettleDate, --结算日期\n"+
" a.Qty,--用于计算\n"+
" (a.Qty-c.WMSDeliveryQty) as SettleWMSDiffQty,--结算与发货差异\n"+
" (a.Qty-a.Qty) as SettleInvoiceDiffQty,--结算与发货差异\n"+
" a.Qty AS InvoiceDiffQty, --开票数量,暂时等同于结算数量\n"+
" d.InvoicePrice,--开票单价\n"+
" (a.Qty * d.InvoicePrice) as InvoiceMoney, --开票金额\n"+
" c.DeliveryOrderNo --出库单号\n"+
" \n"+
" FROM\n"+
" Set_KanBanSettle AS a\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '202109' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode \n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode";