Bugfix in SQL script