Converting SQL output tables to tables