-- Get ASPCAP parameters for stars flagged as known cluster members:
-- In addition to selecting main survey targets, you can
-- select other objects according how they were selected. This is
-- an example of selecting objects chosen to be calibrator stars in
-- clusters with known metallicities (APOGEE_CALIB_CLUSTER).

SELECT TOP 100
   s.apogee_id,s.ra, s.dec, s.glon, s.glat,
   s.vhelio_avg,s.vscatter,
   a.teff, a.teff_err, a.logg, a.logg_err, a.metals, a.metals_err,
   a.alphafe, a.alphafe_err,
   dbo.fApogeeAspcapFlagN(a.aspcapflag),
   dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
   JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
   s.commiss = 0 and
   (s.apogee_target2 & (dbo.fApogeeTarget2('APOGEE_CALIB_CLUSTER')) != 0)
