fixed bug in sql script