Fixed a bug in a SQL statement