Improved SQL statement creation, removed squel, now work with dates