Your SQL command was:
 spectra for stars which have more than 6 visits:
SELECT top 100
 visit.*, aspcap.teff, aspcap.logg, aspcap.param_m_h
FROM apogeeVisit visit
 JOIN apogeeStarVisit starvisit on visit.visit_id = starvisit.visit_id
 JOIN aspcapStar aspcap on aspcap.apstar_id = starvisit.apstar_id
 JOIN apogeeStar star on star.apstar_id = starvisit.apstar_id
WHERE (aspcap.aspxcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
 and (star.apogee_target1 & dbo.fApogeeTarget1('APOGEE_LONG')) > 0
 and star.nvisits > 6 
ORDER BY visit.apogee_id

Your query output (max 500,000 rows):

error_message
error: must be a select statement: spectra for stars which have more than 6 visits: SELECT top 100 visit.*, aspcap.teff, aspcap.logg, aspcap.param_m_h FROM apogeeVisit visit JOIN apogeeStarVisit starvisit on visit.visit_id = starvisit.visit_id JOIN aspcapStar aspcap on aspcap.apstar_id = starvisit.apstar_id JOIN apogeeStar star on star.apstar_id = starvisit.apstar_id WHERE (aspcap.aspxcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0 and (star.apogee_target1 & dbo.fApogeeTarget1('APOGEE_LONG')) > 0 and star.nvisits > 6 ORDER BY visit.apogee_id