Fixed bug in sql statement creation.