" 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"+
" LEFT JOIN (select * from set_backQty WHERE Version='{2}') 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"+
" 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"+
" 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"+
" ) 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"+
" LEFT JOIN (select * from set_backQty WHERE Version='{2}') tt ON temp1.Sap编码 = tt.MaterialCode \n"+
" 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"+
" AND t1.MaterialCode = t2.MaterialCode \n"+
"WHERE\n"+
" t2.HQHKanBan IS NULL";
" t1.* \n"+
"FROM\n"+
" (\n"+
" SELECT\n"+
" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n"+
" left join Set_material b2 on a.MaterialCode = b2.CustomerPartCode \n"+
" WHERE\n"+
" Version = '{0}' \n"+
" AND HQHKanBan <> 'BJ' \n"+
" Set_HQ_H_Platform a\n"+
" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n"+
" {0}\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"+