Fixed an error with creation of flat_table2 sql statements