SELECT custid FROM mainfile group by custid HAVING CNT(*) < 10 INTO cursor lessThan10 SELECT * FROM mainfile where custid in (select * from lessThan10) into table Under10 SELECT * FROM mainfile where custid NOT in (select * from lessThan10) into table Over10thanks again.