" LEFT OUTER JOIN Set_HQ_H_Platform AS b ON a.Kanban = b.HQHKanBan \n"+
" LEFT OUTER JOIN (select * from Set_HQ_H_Platform {0}) 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"+
" AND b.MaterialCode IS NULL {1}\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 set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, WmsBillNum, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode, WmsBillNum, LastModificationTime ) AS a\n"+
" INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n"+
" INNER 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"+
" a.Qty> b.Qty {0}\n"+
" a.Qty> b.Qty {1}\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 set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" AND temp1.订货看板编号 = tt.Code \n"+
" ) UNION2";
var_sql=string.Format(str,condition);
var_sql=string.Format(str,version,condition);
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 "+
" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode ";
" left join Set_material b2 on a.MaterialCode = b2.CustomerPartCode \n"+
" WHERE\n"+
" Version = '{0}' \n"+
" AND HQHKanBan <> 'BJ' \n"+
" ) t1\n"+
" LEFT JOIN ( SELECT HQHKanBan, MaterialCode FROM Set_HQ_H_Platform a WHERE Version = '{0}' AND HQHKanBan <> 'BJ' GROUP BY HQHKanBan, MaterialCode HAVING count(*)> 1 ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n"+
" left join Set_material b2 on a.MaterialCode = b2.CustomerPartCode \n"+
" WHERE\n"+
" Version = '{0}' \n"+
" AND HQHKanBan <> 'BJ' \n"+
" ) t1\n"+
" INNER JOIN ( SELECT HQHKanBan, MaterialCode FROM Set_HQ_H_Platform a WHERE Version = '{0}' AND HQHKanBan <> 'BJ' GROUP BY HQHKanBan, MaterialCode HAVING count(*)> 1 ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n"+