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"+
stringsqlString="SELECT\n"+
"( select ErpMaterialCode, MaterialDesc, SUM(Price) as SumPrice from(\n"+
" * ,\n"+
"select a.ErpMaterialCode, b.SettlementPartCode, a.MaterialDesc, (a.Qty * b.Price) as Price from\n"+
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount, --金额\n"+
"(SELECT ErpMaterialCode, MaterialDesc, SettleMaterialCode, Qty, Version ,CustomerCode \n"+
" ISNULL( InvoicePrice * Qty, 0 ) AS SettleQty, --结算金额\n"+
" (Price-InvoicePrice) as InvoiceDiffPrice, --单价差异\n"+
" ISNULL( Price * Qty-InvoiceMoney, 0 ) AS SumDiffMoney --总金额差异\n"+
" where mdetail.Version='{0}' and mdetail.CustomerCode='{1}' \n"+
"FROM\n"+
") a \n"+
" (\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 "+
" SELECT\n"+
" on r2.MaterialCode=r1.ErpMaterialCode and r2.Version='{0}'\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";