Fixed potential error message in SQL query (#747)