fixed SQL generator