Mary,

Don't issue your spool <filename> command till just before your final select (i.e. the real one)