fix bug in sql statements