Fixed SQL statement bug