Errors in sql code fixed