Review the contents of the SELECT section to make sure that each SELECT statement except the last one ends in a semicolon and that the last one is followed by an END statement. Perhaps you omitted the FORMAT statement at the beginning of that section.