//" ( SELECT SUM ( Qty ) AS Qty, Kanban, MaterialCode, WmsBillNum, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode, WmsBillNum, LastModificationTime ) AS a\n" +
//" LEFT OUTER JOIN ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' ) AS b ON a.Kanban = b.HQHKanBan \n" +
//" AND a.MaterialCode = b.MaterialCode\n" +
//" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" +
//" WHERE\n" +
//" b.HQHKanBan IS NULL \n" +
//" AND b.MaterialCode IS NULL {0}\n" +
//" ) AS temp1\n" +
//" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
//" LEFT JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount GROUP BY HQHKanBan, MaterialCode ) temp3 ON temp1.[订货看板编号] = temp3.HQHKanBan \n" +
" ( SELECT SUM ( Qty ) AS Qty, Kanban, MaterialCode, WmsBillNum, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode, WmsBillNum, LastModificationTime ) AS a\n"+
" LEFT OUTER JOIN ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" b.HQHKanBan IS NULL \n"+
" AND b.MaterialCode IS NULL {0}\n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount GROUP BY HQHKanBan, MaterialCode ) temp3 ON temp1.[订货看板编号] = temp3.HQHKanBan \n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n"+
" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" b.HQHKanBan IS NULL \n"+
" AND b.MaterialCode IS NULL \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n"+
" INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" a.Qty> b.Qty \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" AND temp1.订货看板编号 = tt.Code \n"+
" ) UNION2 \n"+
" ) AS temp\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount GROUP BY HQHKanBan, MaterialCode ) temp3 ON temp.[订货看板编号] = temp3.HQHKanBan \n"+
" AND temp.[客户物料号] = temp3.MaterialCode";
var_sql=string.Format(str,version,contion);
//发运数据中,查出看板号+物料号相同的重复数据
varsql2="SELECT\n"+
" a.WmsBillNum,\n"+
" t1.MaterialCode MaterialCode,\n"+
" a.Kanban ,\n"+
" A.LastModificationTime WmsDate \n"+
"FROM\n"+
" Set_HQ_H_Kanban A\n"+
" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban 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"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode, LastModificationTime ) AS a\n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n"+
" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {0} GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" b.HQHKanBan IS NULL \n"+
" AND b.MaterialCode IS NULL {1}\n"+
" AND b.MaterialCode IS NULL \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN (select * from set_backQty WHERE Version='{2}') tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" LEFT JOIN (select * from set_backQty WHERE Version='{1}') tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode, LastModificationTime ) AS a\n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n"+
" INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode,Price FROM Set_HQ_H_Platform {0} GROUP BY HQHKanBan, MaterialCode,Price ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" a.Qty> b.Qty {1}\n"+
" a.Qty> b.Qty \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n"+
" LEFT JOIN (select * from set_backQty WHERE Version='{2}') tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" LEFT JOIN (select * from set_backQty WHERE Version='{1}') tt ON temp1.Sap编码 = tt.MaterialCode \n"+