" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n"+
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n"+
" AND a.MaterialCode = b.MaterialCode \n"+
" WHERE\n"+
" B.Kanban IS NULL \n"+
" AND B.MaterialCode IS NULL {0} \n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n"+
" ) UNION1 UNION ALL\n"+
"SELECT\n"+
" * \n"+
"FROM\n"+
" (\n"+
" SELECT\n"+
" TEMP1.*,\n"+
" TEMP2.Price,\n"+
" ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n"+
" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n"+
" INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n"+
" AND a.MaterialCode = b.MaterialCode \n"+
" WHERE\n"+
" a.WMSDeliveryQty> B.Qty {0}\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n"+
" ) UNION2";
sql=string.Format(sql,str,contion,version);
//发运数据中,查出看板号+物料号相同的重复数据
varsql2="SELECT\n"+
" a.WMSDeliveryNote WmsBillNum,\n"+
" t1.MaterialCode MaterialCode,\n"+
" a.Kanban ,\n"+
" A.LastModificationTime WmsDate \n"+
"FROM\n"+
" Set_WMSKanBanSettle A\n"+
" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode";
" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode";
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode";
" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate ) A\n"+
" INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban\n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n"+
" AND a.MaterialCode = b.MaterialCode \n"+
" WHERE\n"+
" a.WMSDeliveryQty> B.Qty {0}\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode";